Php 对具有变量的对象调用方法
有谁能解释一下为什么以下方法不起作用:- 我通过以下方式获得输出:-Php 对具有变量的对象调用方法,php,methods,Php,Methods,有谁能解释一下为什么以下方法不起作用:- 我通过以下方式获得输出:- var_dump($this->_payableItem->getNet()); 但当尝试以以下方式访问时,我收到一个错误:- $thresholdUnitMethod = 'getNet()'; $this->_payableItem->$thresholdUnitMethod 错误:- PHP注意:未定义的属性: PayableItem::$getNet()位于 试试这个: $threshold
var_dump($this->_payableItem->getNet());
但当尝试以以下方式访问时,我收到一个错误:-
$thresholdUnitMethod = 'getNet()';
$this->_payableItem->$thresholdUnitMethod
错误:-
PHP注意:未定义的属性:
PayableItem::$getNet()位于
试试这个:
$thresholdUnitMethod = 'getNet';
$this->_payableItem->$thresholdUnitMethod();
这将在\u payableItem
上执行名为getNet
的函数
您可以这样使用:
尝试使用
call\u user\u func()!为什么PHP会阻止将()包含在字符串中?
call_user_func(array($this->_payableItem, 'getNet'));