关于clone关键字
<?php
class Car {
public $name = 'car';
public $speed = 100;
public function __clone() {
$obj = new Car();
$obj->name = $this->name;
}
}
$a = new Car();
var_dump($a);
$b = clone $a;
var_dump($b)
为什么输出的是:
object(Car)#1 (2) {
["name"]=>
string(3) "car"
["speed"]=>
int(100)
}
object(Car)#2 (2) {
["name"]=>
string(3) "car"
["speed"]=>
int(100)
}
即使注释掉__clone()方法也是上述输出呢?