如何在PHP中将对象引用实现为数组字段

如何在PHP中将对象引用实现为数组字段

问题描述:

Is it possible in PHP and how it is implemented, if possible:

$obj = new Build();
$obj['name'] = 'Main;
'$obj['flat'] = 90;
$obj->save();

You can implement ArrayAccess Interface at the object.

Or to wrap into a proxy implementing the ArrayAccess Interface and converting access by index into access to property or into calls to getters/setters.

I would also recommend to consider to use some mapping solution, like JMS Serializeer. JMS can receive an array and map it to an object by defined rules.