How do I access an attribute of an object by name, if I compute the name at runtime?
For instance. I loop over keys and want to get each value of the attributes "field_" . $key.
In python there is getattribute(myobject, attrname).
It works, of course, with eval("$val=$myobject->".$myattr.";");
but IMO this is ugly – is there a cleaner way to do it?
Keep always in mind that a very powerful feature of PHP is its Variable Variables
You can use
or more concisely, using curl brackets