Re: Building variable getter-method
| From: | Jim Lucas | Date: | Thu, 29 May 2014 15:14:48 +0000 |
| Subject: | Re: Building variable getter-method | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-323376@lists.php.net to get a copy of this message | ||
On 05/29/2014 07:06 AM, Michael Bakonyi wrote:
Hi, I'd like to do something like this: if (method_exists($object, 'get' . ucfirst($property))) {Untested, but I do recall having to build a temp variable first, then use it in my call. Also, if you are trying to call a method, you forgot the '()'. So... $method = 'get' . ucfirst($property); $children = $object->$method();
$children = $object->{'get' . ucfirst($property)}; } but this is not working unfortunately – $children is always NULL although the getter exits. Is there a another way to build a dynamic getter? Cheers, Michael-- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/