PHP开发者基本都是万能var_dump,很少echo对象,echo对象默认会报错.
echo对象时默认会自动调用魔术方法__toString
// 1.Object of class a could not be converted to string (报错)
/*
class a{
}
$a = new a();
echo $a;
*/
// 2.正常
class a
{
function __toString()
{
return 'learn c++';
}
}
$a = new a();