toString()
__toString()方法用于一个类被当成字符串时应怎样回应,它是快速获取对象的字符串表示的最便捷的方式,是直接输出对象引用时自动调用的方法
Bash
<?php
class TestClass
{
public $foo;
public function __construct($foo)
{
$this->foo = $foo;
}
public function __toString() {
return $this->foo;
}
}
$class = new TestClass('Hello');
echo $class;//Hello
?>
原文链接:https://www.qiquanji.com/post/7835.html
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

微信扫码关注
更新实时通知