ID: 48937
Updated by: [email protected]
Reported By: software at whatsonyourbrain dot com
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: Win XP SP3
PHP Version: 5.3.0
New Comment:
end() takes the array by reference since it tries to modify the array
(by changing the array pointer) and because there is nowhere to store
that change you end up with that error. If it only returned the last
element, you wouldn't see this warning because it wouldn't need to be
passed by reference.
Previous Comments:
------------------------------------------------------------------------
[2009-07-16 00:47:26] software at whatsonyourbrain dot com
Description:
------------
Using PHP Strict Error Reporting, per Development-mode recommendation,
I encounter a so-called "pass-by-reference" error, yet such a construct
exists neither explicitly, nor apparently in my code. The Strict
Standards Error occurs using the INI directive "error_reporting = E_ALL
| E_STRICT". Extended error data shown below is as available through the
Xdebug extension "php_xdebug-2.0.5-5.3-vc6.dll", the recommended version
for Apache2, win32.
The cause of the error is the use of the internal PHP Programming Data
Structures function, end() [ php.net/end ]. The function takes an array
as a parameter. Although an ampersand is indicated in the prototype of
"end()" in The Manual", there is no cautionary documentation following
in the extended definition of that function, nor is there any apparent
explanation that the parameter is in fact passed by reference. Perhaps
this is /understood/. I did not understand, however, so it was difficult
for me to detect the cause of the error.
With the deprecation of call-time pass-by-reference, the
pass-by-reference quality of the end() parameter should be indicated in
the Manual (in bold-type) to warn programmers that an error WILL occur.
Reproduce code:
---------------
/*
( ! ) Strict standards: Only variables should be passed by reference in
C:\Apache2\htdocs\ww2\class\cwthumbs.class.php on line 15
Call Stack
# Time Memory Function Location
1 1.1758 371912 {main}( ) ..\index.php:0
2 1.1776 449024 require( '..\dochead.inc.php' ) ..\index.php:3
3 1.1965 564360 cwThumbs->getThumbs( $dir = 'css'
) ..\dochead.inc.php:151 */
// END XDEBUG REPORT
// Line 15:
<?php
//...
$itemsArray[]= end(explode('/',$item));
//...
?>
Expected result:
----------------
The contents of a container on the filesystem are passed to the
function, "end()", as an array.
Actual result:
--------------
The contents of a container on the filesystem are passed to the
function, "end()", as an array-- BY REFERENCE-- resulting in a Strict
Standards Error, in "Development" mode*.
*"Development" mode: that which is described in php.ini as the
recommended setting(s) for use in "Development", "Production", or etc.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48937&edit=1