Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法通过引用传递参数1_Php_Syntax Error_Runtime Error - Fatal编程技术网

Php 无法通过引用传递参数1

Php 无法通过引用传递参数1,php,syntax-error,runtime-error,Php,Syntax Error,Runtime Error,因此,我试图检查变量的值是否等于数组的最后一行if($ver==end(Self::Supported_Version){},但结果是无法通过引用传递参数1错误 我的代码:- namespace John; class SP { const Supported_Version = array('a', 'b', 'c'); public function VersionCheck() { return ($ver == end(Self::Supporte

因此,我试图检查变量的值是否等于数组的最后一行
if($ver==end(Self::Supported_Version){}
,但结果是
无法通过引用传递参数1
错误

我的代码:-

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));

无法创建对常量的引用,因为它无法更改,
end()
通过引用获取参数….,但您可以简单地将常量复制到临时变量并使用它:
$sv=Self::Supported\u Version;return($ver==end($sv)?(True):(False));
或不要使用常量。为什么需要它?哦…谢谢你们两位(@abracadver@jh1711),它也可以工作。@abracadver因为它不再被更改,它只包含一个数组,其中包含一个支持/允许的版本列表。。。