#38626 [Opn->WFx]: Passing not variables by Reference

From: Date: Mon, 28 Aug 2006 13:33:23 +0000
Subject: #38626 [Opn->WFx]: Passing not variables by Reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-101435@lists.php.net to get a copy of this message
ID: 38626 Updated by: tony2001@php.net Reported By: php at swapo dot de -Status: Open +Status: Wont fix Bug Type: Feature/Change Request Operating System: all PHP Version: 5.1.5 New Comment: >$extension = @array_pop(explode('.', $filename)); explode(..) is not a variable, hence it can't be passed by reference. Previous Comments: ------------------------------------------------------------------------ [2006-08-28 12:43:48] php at swapo dot de Description: ------------ The behaviour of pass by reference is a little odd. As stated here (http://www.php.net/manual/en/language.references.pass.php) passing by reference works only if you use a variable as a function argument. This is also the case with builtin functions like array_pop but I can think of many situations when it makes sense to use a function's return value as an argument to another function. A common example (perhaps not the best though) is to get a file extension by combining explode and array_pop. This wasn't a problem until PHP 5.1 and I think it shouldn't be now. Reproduce code: --------------- // doesn't work $extension = array_pop(explode('.', $filename)); // works $parts = explode('.', $filename); $extension = array_pop($parts); unset($parts); // surpressing the error message works too $extension = @array_pop(explode('.', $filename)); Expected result: ---------------- All examples should give the same result. Actual result: -------------- The first example results in an error message as the argument for array_pop must be a variable: Strict Standards: Only variables should be passed by reference ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38626&edit=1

« previous php.bugs (#101435) next »