【发布时间】:2015-10-11 15:21:45
【问题描述】:
__toString在PHP中有什么用处?
例如,我有一个函数,例如(在一个名为 person 的类中)
public function __construct($id, $name) {
$this->id = $id;
$this->name= $name;
}
和
$person= new person("12","James");
$person->setDescription("Test Description");
$person->setImage("Test Image");
如何使用__toString 获取这些数据并将它们打印在一行上。
例如: 12 测试说明詹姆斯测试图片
【问题讨论】: