【发布时间】:2018-09-13 23:56:08
【问题描述】:
- 我有 getFoo、getBar 方法
- 我有数组 [Foo, bar]
- 我想在循环中动态获取方法
示例:
class Item {
getFoo();...
getBar();...
}
$methods = ['Foo','Bar'];
...
foreach($methods as $method){
$methodName = 'get'.$method.'()';
$item->{$methodName}; //Notice: Undefined property: Item::$getFoo()
}
//"Item->$getFoo()" instead of "Item->getFoo()" probleme is $
【问题讨论】:
标签: php object methods concatenation