所以我试图检查变量的值是否等于数组的最后一行if($ver == end(Self::Supported_Version) {}
,但导致Cannot Pass Parameter 1 by reference
错误...
我的代码:
namespace John;
class SP {
const Supported_Version = array('a', 'b', 'c');
public function VersionCheck()
{
return ($ver == end(Self::Supported_Version) ? (True) : (False));
}
}
最佳答案
您无法创建对常量的引用,因为无法对其进行更改,并且end()
通过引用接受参数。如果您确实需要一个常量,则分配给一个临时变量。您可以在通话中执行此操作。
另外,您不需要三元,因为==
比较将返回true
或false
:
return ($ver == end($s = Self::Supported_Version));
关于php - 无法通过引用传递参数1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49224820/