php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #10120 implode(), if empty elements exist
Submitted: 2001-04-02 15:17 UTC Modified: 2002-06-08 11:11 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: christian dot krause at metis dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.0.6 OS: any
Private report: No CVE-ID: None
 [2001-04-02 15:17 UTC] christian dot krause at metis dot 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-01 16:57 UTC] sniper@php.net
reproduced with PHP 4.0.6RC1.

 [2001-10-15 12:52 UTC] christian dot krause at metis dot 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-10-15 16:03 UTC] jeroen@php.net
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)
}

 [2002-06-07 20:44 UTC] mfischer@php.net
Honestly, I think changing this now in PHP4 is bad. It behaved that way since 4.0, so changing it with 4.3 is just silly. This asks for more trouble that we would gain.

Moving over to documentation problem.
 [2002-06-08 11:11 UTC] mfischer@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 04:01:30 2024 UTC