Re: Building variable getter-method
| From: | Jim Lucas | Date: | Thu, 29 May 2014 15:22:31 +0000 |
| Subject: | Re: Building variable getter-method | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-323378@lists.php.net to get a copy of this message | ||
On 05/29/2014 08:14 AM, Jim Lucas wrote:
On 05/29/2014 07:06 AM, Michael Bakonyi wrote:Better yet, rearrange things a little. $method = 'get' . ucfirst($property); if ( method_exists($object, $method) ) { $children = $object->$method(); }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)}; }
-- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/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