在
PHP中是否可以更改Objects属性键/名称?例如:
stdClass Object
(
[cpus] => 2
[created_at] => 2011-05-23T01:28:29-07:00
[memory] => 256
)
我希望将键create_at更改为在Object中创建,留下一个如下所示的对象:
stdClass Object
(
[cpus] => 2
[created] => 2011-05-23T01:28:29-07:00
[memory] => 256
)
$object->created = $object->created_at; unset($object->created_at);
像适配器类似的东西可能是一个更强大的选择,尽管取决于这个操作在何处以及需要多长时间.
class PC {
public $cpus;
public $created;
public $memory;
public function __construct($obj) {
$this->cpus = $obj->cpu;
$this->created = $obj->created_at;
$this->memory = $obj->memory;
}
}
$object = new PC($object);
