0

Possible Duplicate:
Get PHP class property by string

Is there a cleaner way to do this? it does not compile

$object1->name = 'my_name';
$object1->address = 'address';
$object2->somefield->($object1->name) = $object1;

it works only if i assign to another variable $object1->name

$object1->name = 'my_name';
$object1->address = 'address';
$temp = $object1->name;
$object2->somefield->$temp = $object1;
Community
  • 1
  • 1
Pulz
  • 29
  • 7

1 Answers1

9

Try this:

$object2->somefield->{$object1->name} = $object1;
aykut
  • 2,984
  • 24
  • 26