有更清洁的方法吗?它没有编译
$object1->name = 'my_name';
$object1->address = 'address';
$object2->somefield->($object1->name) = $object1;
仅当我分配给另一个变量$ object1-> name
时,它才有效$object1->name = 'my_name';
$object1->address = 'address';
$temp = $object1->name;
$object2->somefield->$temp = $object1;
答案 0 :(得分:9)
试试这个:
$object2->somefield->{$object1->name} = $object1;