我很好奇在PHP OOP中编写链接接口。我从php.net网站修改了这个示例代码,我想进一步说明 - 我怎样才能从这种接口返回对象或数组?如何从PHP OOP中的链接接口返回对象或数组?
// Declare a simple class
class TestClass
{
public $foo;
public function __construct($foo)
{
$this->foo = $foo;
}
public function __toString()
{
return $this->foo;
}
}
$input = (object)array("title" => "page 1");
$class = new TestClass($input);
echo $class;
错误,
Catchable fatal error: Method TestClass::__toString() must return a string value in C:\wamp\www\test\2013\php\fluent_interface.php on line 2
我应该使用不同的魔术方法,而不是__toString
呢?
编辑: 我能回到这是我的结果,
stdClass Object ([title] => page 1)
你究竟想要做什么? – Dragony
请参阅我上面的修改。谢谢。 – laukok