21 quizzes found.

What are the values of $a in $obj_one and $obj_two when this script is executed?

<?phpclass 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();?>
  1. 10,20
  2. You cannot modify private member variables of a different class
  3. 20,20
  4. 10,10
  5. 20,10

Choose 1 answers

What are the three access modifiers that you can use in PHP objects?

  1. protected
  2. public
  3. static
  4. private
  5. final

Choose 3 answers

Static is used for variables and methods but it's not considered an access method. A final class is a class that cannot be extended.

When checking to see if two variables contain the same instance of an object, which of the following comparisons should be used?

  1. if($obj1->equals($obj2) && ($obj1 instanceof $obj2))
  2. if($obj1->equals($obj2))
  3. if($obj1 === $obj2)
  4. if($obj1 instanceof $obj2)
  5. if($obj1 == $obj2)

Choose 1 answers

What is wrong with the following code?

<?phpfunction duplicate($obj) {$newObj = $obj;return $newObj;}$a = new MyClass();$a_copy = duplicate($a);$a->setValue(10);$a_copy->setValue(20);?>
  1. You must use return &$newObj instead
  2. There is nothing wrong with this code
  3. duplicate() must accept its parameter by reference
  4. You must use the clone operator to make a copy of an object
  5. duplicate() must return a reference

Choose 1 answers

How can you modify the copy of an object during a clone operation?

  1. Put the logic in the object's constructor to alter the values
  2. Implment your own function to do object copying
  3. Implement the object's __clone() method
  4. Implement __get() and __set() methods with the correct logic
  5. Implement the __copy() method with the correct logic

Choose 1 answers