note 64065 added to function.list
| From: | dolan at teamsapient dot com | Date: | Thu, 06 Apr 2006 18:08:24 +0000 |
| Subject: | note 64065 added to function.list | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107464@lists.php.net to get a copy of this message | ||
I noticed w/ version 5.1.2, the behavior of list() has changed (this occurred at some point between
version 5.0.4 and 5.1.2). When re-using a variable name in list() that list() is being assigned to,
instead of the values being assigned all at once, the reused variable gets overwritten before all
the values are read.
Here's an example:
** disclaimer: obviously this is sloppy code, but I want to point out the behavior change (in case
anyone else comes across similar code) **
<?
$data = array();
$data[] = array("value1", "value2", "value3", "value4");
$data[] = array("value1", "value2", "value3", "value4");
$data[] = array("value1", "value2", "value3", "value4");
$data[] = array("value1", "value2", "value3", "value4");
foreach($data as $record)
{
list($var1, $var2, $var3, $record) = $record;
echo "var 1: $var1, var 2: $var2, var 3: $var3, record: $record\\n";
}
?>
OUTPUT on version 5.0.4:
var 1: value1, var 2: value2, var 3: value3, record: value4
var 1: value1, var 2: value2, var 3: value3, record: value4
var 1: value1, var 2: value2, var 3: value3, record: value4
var 1: value1, var 2: value2, var 3: value3, record: value4
OUTPUT on version 5.1.2:
var 1: v, var 2: a, var 3: l, record: value4
var 1: v, var 2: a, var 3: l, record: value4
var 1: v, var 2: a, var 3: l, record: value4
var 1: v, var 2: a, var 3: l, record: value4
----
Server IP: 216.194.113.175
Probable Submitter: 207.145.121.114
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.list.php
Edit -- http://master.php.net/note/edit/64065
Del: integrated -- http://master.php.net/note/delete/64065/integrated
Del: useless -- http://master.php.net/note/delete/64065/useless
Del: bad code -- http://master.php.net/note/delete/64065/bad+code
Del: spam -- http://master.php.net/note/delete/64065/spam
Del: non-english -- http://master.php.net/note/delete/64065/non-english
Del: in docs -- http://master.php.net/note/delete/64065/in+docs
Del: other reasons-- http://master.php.net/note/delete/64065
Reject -- http://master.php.net/note/reject/64065
Search -- http://master.php.net/manage/user-notes.php