致命错误:Uncaught ArgumentCounter错误:函数类的参数太少::_construct(),传入0,PHP7.1中应至少有1个参数
我正在学习PHP,但遇到了一个新问题。如果你能帮忙,我将不胜感激 我的代码:致命错误:Uncaught ArgumentCounter错误:函数类的参数太少::_construct(),传入0,PHP7.1中应至少有1个参数,php,php-7.1,Php,Php 7.1,我正在学习PHP,但遇到了一个新问题。如果你能帮忙,我将不胜感激 我的代码: $idTrack = (new Track_Obj)->getIdtCommon($a,$b); 错误: Uncaught ArgumentCountError:函数Track_Obj::__构造的参数太少,传入0,PHP7.1中至少应有1个参数 解决: 新代码: $idTrack = (new Track_Obj($idtakip))->getIdtCommon($a,$b); or
$idTrack = (new Track_Obj)->getIdtCommon($a,$b);
错误:
Uncaught ArgumentCountError:函数Track_Obj::__构造的参数太少,传入0,PHP7.1中至少应有1个参数
解决:
新代码:
$idTrack = (new Track_Obj($idtakip))->getIdtCommon($a,$b);
or
$class=new Track_Obj($idtakip);
$idTrack = $class->getIdtCommon($a,$b);
感谢您的帮助和解释@Phil$a不能为空$idtakip必须在创建Track类对象时传递,$a不为空,这是示例值,您认为像$a=1。@jakub wrona您可以这样说:$idTrack=new Track\u Obj$idtakip->getIdtCommon$a,$b?但是我不使用$idtakipTo来解释,新的Track_Obj或者更实际的新Track_Obj调用Track_Obj构造函数。该构造函数有一个必需的参数$idtakip和一个可选的$env。您需要为$idtakip提供至少一个参数,例如new Track_Obj$something。我不建议在创建类实例时省略括号,因为它只会让代码读起来很混乱,比如新的东西;❌ 新事物;✔️
$idTrack = (new Track_Obj($idtakip))->getIdtCommon($a,$b);
or
$class=new Track_Obj($idtakip);
$idTrack = $class->getIdtCommon($a,$b);