全等:而如果使用全等运算符(===),这两个对象变量一定要指向某个类的同一个实例(即同一个对象,说明对象标志符都完全一样)。 class Sheep
{
public $name;
protected $food;
public function __construct(string $name, string $food)
{
$this->name = $name;
$this->food = $food;
}
public function __toString()
{
return serialize($this);
}
public function __clone()
{
echo '对象被克隆' . PHP_EOL;
}
}
$sheep1 = new Sheep('喜洋洋', '肉');//PHP Recoverable fatal error: Object of class Sheep could not be converted to string
echo $sheep1;