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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sb at cis dot ch
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 20:01:32 2024 UTC