__toString
文章目录
<?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

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论