1. Question: What are the values of $a in $obj_one and $obj_two when this script is executed?
    <?php
    class myClass {
      private $a;
    
      public function __construct() {
        $this->a = 10;
      }
    
      public function printValue() {
        print "The Value is: {$this->a}\n";
      }
    
      public function changeValue($val, $obj = null) {
        if(is_null($obj)) {
          $this->a = $val;
        } else {
          $obj->a = $val;
        }
      }
    
      public function getValue() {
        return $this->a;
      }
    }
    
    $obj_one = new myClass();
    $obj_two = new myClass();
    
    $obj_one->changeValue(20, $obj_two);
    $obj_two->changeValue($obj_two->getValue(), $obj_one);
    
    $obj_two->printValue();
    $obj_one->printValue();
    
    ?>

    A
    10,20

    B
    You cannot modify private member variables of a different class

    C
    20,20

    D
    10,10

    E
    20,10

    Note: Not available
    1. Report
  2. Question: What are the three access modifiers that you can use in PHP objects?

    A
    protected

    B
    public

    C
    static

    D
    private

    E
    final

    Note: Not available
    1. Report
  3. Question: When checking to see if two variables contain the same instance of an object, which of the following comparisons should be used?

    A
    if($obj1->equals($obj2) && ($obj1 instanceof $obj2))

    B
    if($obj1->equals($obj2))

    C
    if($obj1 === $obj2)

    D
    if($obj1 instanceof $obj2)

    E
    if($obj1 == $obj2)

    Note: Not available
    1. Report
  4. Question: In PHP 5 you can use the ______ operator to ensure that an object is of a particular type. You can also use _______ in the function declaration.

    A
    instanceof, is_a

    B
    instanceof, type-hinting

    C
    type, instanceof

    D
    ===, type-hinting

    E
    ===, is_a

    Note: Not available
    1. Report
  5. Question: What is wrong with the following code?
    <?php
    
    function duplicate($obj) {
    	$newObj = $obj;
    	return $newObj;
    }
    
    $a = new MyClass();
    
    $a_copy = duplicate($a);
    
    $a->setValue(10);
    $a_copy->setValue(20);
    
    ?>

    A
    You must use return &$newObj instead

    B
    There is nothing wrong with this code

    C
    duplicate() must accept its parameter by reference

    D
    You must use the clone operator to make a copy of an object

    E
    duplicate() must return a reference

    Note: Not available
    1. Report
  6. Question: How can you modify the copy of an object during a clone operation?

    A
    Put the logic in the object's constructor to alter the values

    B
    Implment your own function to do object copying

    C
    Implement the object's __clone() method

    D
    Implement __get() and __set() methods with the correct logic

    E
    Implement the __copy() method with the correct logic

    Note: Not available
    1. Report
  7. Question: What is the primary difference between a method declared as static and a normal method?

    A
    Static methods can only be called using the :: syntax and never from an instance

    B
    Static methods do not provide a reference to $this

    C
    Static methods cannot be called from within class instances

    D
    Static methods don't have access to the self keyword

    E
    There is no functional difference between a static and non-static method

    Note: Not available
    1. Report
  8. Question: What is the output of the following script?
    <?php
    
    class ClassOne {
      protected $a = 10;
    
      public function changeValue($b) {
        $this->a = $b;
      }
    }
    
    class ClassTwo extends ClassOne {
    
      protected $b = 10;
    
      public function changeValue($b) {
        $this->b = 10;
        parent::changeValue($this->a + $this->b);
      }
    
      public function displayValues() {
        print "a: {$this->a}, b: {$this->b}\n";
      }
    }
    
    $obj = new ClassTwo();
    
    $obj->changeValue(20);
    $obj->changeValue(10);
    
    $obj->displayValues();
    
    ?>

    A
    a: 30, b: 30

    B
    a: 30, b: 20

    C
    a: 30, b: 10

    D
    a: 20, b: 20

    E
    a: 10, b: 10

    Note: Not available
    1. Report
  9. Question: The ______ keyword is used to indicate an incomplete class or method, which must be further extended and/or implemented in order to be used.

    A
    final

    B
    protected

    C
    incomplete

    D
    abstract

    E
    implements

    Note: Not available
    1. Report
  10. Question: To ensure that a given object has a particular set of methods, you must provide a method list in the form of an ________ and then attach it as part of your class using the ________ keyword.

    A
    array, interface

    B
    interface, implements

    C
    interface, extends

    D
    instance, implements

    E
    access-list, instance

    Note: Not available
    1. Report
Copyright © 2024. Powered by Intellect Software Ltd