Re: Building variable getter-method

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/29/14, 9:06 AM, Michael Bakonyi wrote:
Hi,

I'd like to do something like this:

if (method_exists($object, 'get' . ucfirst($property))) {
   $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

Side note: PHP is, technically, case-insensitive for class/function/method names. So you don't need the ucfirst() calls. Calling $object->foo() and $object->Foo() do the same thing.

--Larry Garfield

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux