suchen
Heimphp教程php手册Strict Standards: Only variables should be passed by referen

本文章来给大家介绍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等等

Stellungnahme
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

Video Face Swap

Video Face Swap

Tauschen Sie Gesichter in jedem Video mühelos mit unserem völlig kostenlosen KI-Gesichtstausch-Tool aus!

Heiße Werkzeuge

SublimeText3 Englische Version

SublimeText3 Englische Version

Empfohlen: Win-Version, unterstützt Code-Eingabeaufforderungen!

VSCode Windows 64-Bit-Download

VSCode Windows 64-Bit-Download

Ein kostenloser und leistungsstarker IDE-Editor von Microsoft

PHPStorm Mac-Version

PHPStorm Mac-Version

Das neueste (2018.2.1) professionelle, integrierte PHP-Entwicklungstool

WebStorm-Mac-Version

WebStorm-Mac-Version

Nützliche JavaScript-Entwicklungstools

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools