Bug #53332 [Opn->Csd]: list() uses overwritten variable

From: Date: Wed, 11 Apr 2012 12:40:50 +0000
Subject: Bug #53332 [Opn->Csd]: list() uses overwritten variable
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8241@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=53332&edit=1 ID: 53332 Updated by: nikic@php.net Reported by: sb at cis dot ch Summary: list() uses overwritten variable -Status: Open +Status: Closed Type: Bug Package: Documentation problem PHP Version: 5.2.14 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2010-11-17 17:07:00] 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: -------------- # ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=53332&edit=1

« previous php.doc.bugs (#8241) next »