Re: Building variable getter-method

From: Date: Thu, 29 May 2014 15:20:22 +0000
Subject: Re: Building variable getter-method
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-323377@lists.php.net to get a copy of this message
On 29 May 2014, at 15:06, Michael Bakonyi <kontakt@mb-neuemedien.de> wrote: > I'd like to do something like this: > > if (method_exists($object, 'get' . ucfirst($property))) { > $children = $object->{'get' . ucfirst($property)}; The line above is not calling a method, it’s accessing a member variable. The following might work (note the added brackets at the end), but if not you’ll need to put the name of the method in to a temporary variable as Jim suggests. $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? -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/

« previous php.general (#323377) next »