Home  >  Article  >  Backend Development  >  Strict Standards: Only variables should be passed by referen_PHP教程

Strict Standards: Only variables should be passed by referen_PHP教程

WBOY
WBOYOriginal
2016-07-13 10:57:351163browse

This article will introduce to you the solution to Strict Standards: Only variables should be passed by reference in. Friends can refer to it.

Use the built-in reset function in php to get the value of the first element of the array. For example:

//The output result is one. For the following code, if "Strict Standards" is turned on in PHP, you will see the prompt "Strict Standards: Only variables should be passed by reference in".
The code is as follows
 代码如下 复制代码

$arr = array('one', 'two', 'three');

echo reset($arr);  

Copy code

 代码如下 复制代码

$str = 'netingcn.com';

echo reset(explode('.', $str));

$arr = array('one', 'two', 'three');

echo reset($arr);

The code is as follows
Copy code

$str = 'netingcn.com';echo reset(explode('.', $str)); Why is this happening? You can first take a look at the definition of the reset function: function reset (array &$array) {}As you can see from the definition, the parameter accepted by reset is a reference to an array. The return value of explode in the above code is not a reference to any array, so there will be the above prompt under "Strict Standards". The solution is very simple, just write reset(explode('.', $str)) in two steps. The first step is to assign the return value of explode to a variable, and the second step is to use this variable as the reset parameter. The above prompt is not just for the reset function. As long as the parameter accepts an object reference and the function return value is used directly to pass the value, you will see such a prompt. For example, built-in array_pop, shuffle, curent, next, prev, next, etc.
http://www.bkjia.com/PHPjc/632075.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632075.htmlTechArticleThis article will introduce to you the solution to Strict Standards: Only variables should be passed by reference in. Friends can refer to it. . Use the built-in reset function in php to get the array...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn