Re: Building variable getter-method
| From: | Michael Bakonyi | Date: | Mon, 02 Jun 2014 09:12:05 +0000 |
| Subject: | Re: Building variable getter-method | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-323384@lists.php.net to get a copy of this message | ||
Great, thx a lot for your help! :)
Cheers,
Michael
--
Michael Bakonyi
Alstater Str. 55
69124 Heidelberg
Tel: 0170 40 232 62
Skype: m.bakonyi
Am 29.05.2014 um 17:22 schrieb Jim Lucas:
> On 05/29/2014 08:14 AM, Jim Lucas wrote:
>> 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)};
>>> }
>
> Better yet, rearrange things a little.
>
> $method = 'get' . ucfirst($property);
>
> if ( method_exists($object, $method) ) {
> $children = $object->$method();
> }
>
>>>
>>> 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/