【发布时间】:2015-06-09 08:58:30
【问题描述】:
我正在根据从 API 响应中获得的数据创建人员实例。
数据返回为 \stdClass,我想将其转换为我自己的对象。 有没有办法传递构造函数中的所有调用并使之更优雅?
Class Person
{
protected $Name;
protected $Email;
...
protected $Property40;
**// Is there an elegant way to do it? Assuming I know all the property names**
public function __construct(\stdClass $person)
{
$this->Name = $person->Name;
$this->EMail = $person->EMail;
...
$this->Property40 = $person->Property40
}
}
Tnx
【问题讨论】:
标签: php constructor dynamic-binding