在这里,学生的类方法和变量也会受到影响并出现在其他对象中,例如$obj1,为什么会发生这种情况?
class Student {
public $name;
public $age;
public function callme() {
return 'called';
}
}
$obj = new Student();
$obj1 = $obj;
$obj->name = 'David';
$obj->age = 12;
echo '<pre>';
print_r($obj);
print_r($obj1);
echo $obj1->callme();
输出:
Student Object
(
[name] => David
[age] => 12
)
Student Object
(
[name] => David
[age] => 12
)
called
转载请注明出处:http://www.bizarre-animals.com/article/20230331/2192437.html