|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-07-16 00:47 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 11:00:02 2025 UTC |
Not at all, simply do: $parts = explode('/',$item); $itemsArray[]= end($parts); If you want to use end() in this case.