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);
-
- ?>
- <?php
- function duplicate($obj) {
- $newObj = $obj;
- return $newObj;
- }
- $a = new MyClass();
- $a_copy = duplicate($a);
- $a->setValue(10);
- $a_copy->setValue(20);
- ?>
A
B
C
D
E
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