我有
示例:
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 $
发布于 2018-09-14 08:13:22
class Item {
getFoo();...
getBar();...
}
$methods = ['Foo','Bar'];
...
foreach($methods as $method){
$methodName = 'get'.$method;//this is the good way
$item->$methodName();//the bracket make PHP consider this as function call instead of a simple property
}
https://stackoverflow.com/questions/52323230
复制相似问题