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;
0

1 Answer 1

9

Try this:

$object2->somefield->{$object1->name} = $object1;
Sign up to request clarification or add additional context in comments.

3 Comments

+1, even this answer got too much up-votes :P
Good! Thank you!! It there some documentation to this somewhere? :)
php.net/manual/en/language.types.string.php (under the 'Complex (curly) syntax' title)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.