Bug #10120 Updated: implode(), if empty elements exist
| From: | jeroen@php.net | Date: | Mon, 15 Oct 2001 20:03:04 +0000 |
| Subject: | Bug #10120 Updated: implode(), if empty elements exist | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-67975@lists.php.net to get a copy of this message | ||
ID: 10120
Updated by: jeroen
Reported By: christian.krause@metis.de
Status: Analyzed
Old Bug Type: Arrays related
Bug Type: Scripting Engine problem
Old Operating System: Win 98se
Operating System: any
PHP Version: 4.0.6
New Comment:
The problem: list(<a>,<b>) will assign to <b> first, and only then to <a>.
This is the case in all versions of PHP 4 (don't know for PHP 3). Usually this assignment order
doesn't matter, but in this case it does.
(reclassified, analyzed now (was already marked analyzed?))
<?php
list($ar['a'],$ar['b']) = array(1,2);
var_dump($ar);
?>
array(2) {
["b"]=>
int(2)
["a"]=>
int(1)
}
Previous Comments:
------------------------------------------------------------------------
[2001-10-15 12:52:53] christian.krause@metis.de
The result of implode() is in a wrong order, if a "named index" is used.
Example exploding and imploding a string (seperated by "+"):
$a = "11+12+13+14";
echo ("a befor execution: ".$a."<BR>");
echo ("this works: ".implode("+", explode("+",
$a))."<BR>");
list(
$r["A"],
$r["B"],
$r["C"],
$r["D"]) = explode("+", $a);
echo ("r between execution:
".$r["A"].$r["B"].$r["C"].$r["D"]."<BR>");
$a = implode("+", $r);
echo ("a after execution: ".$a."<BR>");
Output:
a befor execution: 11+12+13+14
this works: 11+12+13+14
r between execution: 11121314
a after execution: 14+13+12+11
The values in the last row have the wrong order.
------------------------------------------------------------------------
[2001-06-01 16:57:11] sniper@php.net
reproduced with PHP 4.0.6RC1.
------------------------------------------------------------------------
[2001-04-02 15:17:43] christian.krause@metis.de
exploding and imploding a string (seperated by "+"):
$a = "11+12+13+14+++++++++";
echo ("a befor execution: ".$a."<BR>");
list(
$r["A"],
$r["B"],
$r["C"],
$r["D"],
$r["E"],
$r["F"],
$r["G"],
$r["H"],
$r["I"],
$r["J"],
$r["K"],
$r["L"],
$r["M"]) = explode("+", $a);
$a = implode("+", $r);
echo ("a after execution: ".$a."<BR>");
I expect an output (like PHP 3.0.17):
a befor execution: 11+12+13+14+++++++++
a after execution: 11+12+13+14+++++++++
but the output is (in current version):
a befor execution: 11+12+13+14+++++++++
a after execution: +++++++++14+13+12+11
after execution the string is vis versus. It happens only if I try to implode emty elements. The
behaviour is different to PHP 3.0.X
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=10120&edit=1