本文章来给大家介绍strict standards: only variables should be passed by reference in解决办法,各位朋友可参考。
php中使用内置的reset函数可以获取array的第一个元素的值。例如:
代码如下 复制代码
$arr = array('one', 'two', 'three');
echo reset($arr);
// 输出的结果为 one对于下述代码,如果php开启了strict standards,将会看到strict standards: only variables should be passed by reference in的提示。
代码如下 复制代码
$str = 'netingcn.com';
echo reset(explode('.', $str));
为什么会这样呢?可以先看看reset函数的定义:
function reset (array &$array) {}从定义中可以看到,reset接受的参数是一个array的引用。而上述代码中explode返回值不是任何array的引用,所以在strict standards下会有上述提示。解决办法很简单,只需要把reset(explode('.', $str))分两步写即可。第一步先把explode的返回值赋给一个变量,第二步把这个变量作为reset参数。
出现上面的提示的不只是reset函数,只要参数接受的是对象引用,而传值直接使用function返回值都会看到那样的提示。例如内置的array_pop、shuffle、curent、next、prev、next等等
http://www.bkjia.com/phpjc/632075.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/632075.htmltecharticle本文章来给大家介绍strict standards: only variables should be passed by reference in解决办法,各位朋友可参考。 php中使用内置的reset函数可以获取array的...