php中使用内置的reset函数可以获取array的第一个元素的值。例如: $arr = array('one', 'two', 'three');echo reset($arr); // 输出的结果为 one 对于下述代码,如果php开启了“Strict Standards”,将会看到“Strict Standards: Only variables should be p
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等等。
原文地址:Strict Standards: Only variables should be passed , 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
