UI Developer
UI Developer

Reputation: 183

call the get_ method of the object

I have

foreach ($constructor_param_names as $reflectionParameter ){
            $constructor_params[] = $reflectionParameter -> getName();
            $property = $reflectionParameter -> getName();

//how to call the get____ method of the object
//to get the param value (of that parameter name)
            $value = $reflectionParameter-> ...
}

Upvotes: 0

Views: 265

Answers (1)

Jon
Jon

Reputation: 437386

This is explained in the documentation for variable methods.

For an instance method:

$methodName = 'get_'.$property;
$value = $object->$methodName();

There are also other ways to call the getter (e.g. call_user_func and ReflectionMethod::invoke) but this is the most straightforward.

Also note that function and method names in PHP are case-insensitive, so there is no need to pay attention to capitalization.

Upvotes: 2

Related Questions