php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53332 list() uses overwritten variable
Submitted: 2010-11-17 17:07 UTC Modified: 2012-04-11 12:40 UTC
From: sb at cis dot ch Assigned: nikic (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.2.14 OS:
Private report: No CVE-ID: None
 [2010-11-17 17:07 UTC] sb at cis dot ch
Description:
------------
When a parameter to list() and the variable assigned to it are the same (that means list(...,$a)=$a;), list()  uses the new value of the variable (once it's been overwritten) and reads the remaining parameters from this new value. This is surprising and undocumented behaviour. It would be better if list() kept assigning values from the originally assigned array. The problem exists in PHP 5.3.2-2 too.

This is not important, just surprising. Array variables usually get named distinctly from other variables, so the conflict doesn't surface often.

Test script:
---------------
$n=array("b","#123");
list($b,$n)=$n; // Currently equivalent to "$n=$n[1]; $b=$n[0];"
echo $b;


Expected result:
----------------
b

Actual result:
--------------
#

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-15 19:16 UTC] felipe@php.net
-Package: Scripting Engine problem +Package: Documentation problem
 [2012-04-11 12:40 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2012-04-11 12:40 UTC] nikic@php.net
Closing as this was already added to the docs in the meantime:

> Modification of the array during list() execution (e.g. using list($a, $b) = $b) results in undefined behavior.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC