gandalf0777 Posted July 8, 2009 Share Posted July 8, 2009 Hi, I am wondering if it is a possibility to get an object property as in the following example: $CFG->example_field = 'something'; $field = "example_field"; print $CFG->$field; ??? does not work of course print $CFG[$field]; ??? does not work of course So I would like to have some kind of converting a string "example_field" to a name of the property of the $CFG object. Anobody knows is this possible or not? Regards, Pawel Quote Link to comment https://forums.phpfreaks.com/topic/165163-getting-objects-property-by-giving-a-string/ Share on other sites More sharing options...
ignace Posted July 8, 2009 Share Posted July 8, 2009 print $CFG->{$field}; Quote Link to comment https://forums.phpfreaks.com/topic/165163-getting-objects-property-by-giving-a-string/#findComment-870871 Share on other sites More sharing options...
gandalf0777 Posted July 8, 2009 Author Share Posted July 8, 2009 Works like a charm! Thank you very much, Best regards, Pawel Quote Link to comment https://forums.phpfreaks.com/topic/165163-getting-objects-property-by-giving-a-string/#findComment-870874 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.