Home php教程 php手册 Strict Standards: Only variables should be passed

Strict Standards: Only variables should be passed

Jun 06, 2016 pm 08:10 PM
only variable

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
Copy after login

对于下述代码,如果php开启了“Strict Standards”,将会看到“Strict Standards: Only variables should be passed by reference in”的提示。

$str = 'netingcn.com';
echo reset(explode('.', $str));
Copy after login

为什么会这样呢?可以先看看reset函数的定义:

function reset (array &$array) {}
Copy after login

从定义中可以看到,reset接受的参数是一个array的引用。而上述代码中explode返回值不是任何array的引用,所以在“Strict Standards”下会有上述提示。解决办法很简单,只需要把reset(explode(‘.’, $str))分两步写即可。第一步先把explode的返回值赋给一个变量,第二步把这个变量作为reset参数。

出现上面的提示的不只是reset函数,只要参数接受的是对象引用,而传值直接使用function返回值都会看到那样的提示。例如内置的array_pop、shuffle、curent、next、prev、next等等。

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)