调用对象的get_方法


call the get_ method of the object

我有

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-> ...
}

这在变量方法的文档中有解释。

对于一个实例方法:

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

还有其他方法可以调用getter(例如call_user_funcReflectionMethod::invoke),但这是最直接的。

还要注意,PHP中的函数和方法名称不区分大小写,因此不需要注意大写。