php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25671 nested array with str_replace
Submitted: 2003-09-26 11:51 UTC Modified: 2003-09-27 16:48 UTC
From: ivan dot lamouret at caramail dot com Assigned:
Status: Closed Package: Strings related
PHP Version: 4.3.3 OS: *
Private report: No CVE-ID:
 [2003-09-26 11:51 UTC] ivan dot lamouret at caramail dot com
Description:
------------
after calling str_replace on a nested array the resulting array changes values unexpectedly. Note that in the code below, there is no reference in the array values.

while trying different versions the code (reducing the size from my original code), the value of 
$fixed["firstlevel"] came also as :
&NULL
&UNKNOWN:0
bar
tostr
...
that may be related to Bug #23654?

regards,

Ivan

Reproduce code:
---------------
function foo ($someuselessvar,$str){
	$local=str_replace("fromstr","tostr",$str);
}
//----------------------------------------------/
function bar($var){
	$result=array();
	$result["firstlevel"]["secondlevel"]="$var";//unquote will change behavior!
	foo("someuselessstring", $result);
	return $result;
}
$first="foooo";
//$first="foooooooo";
$fixed=bar("$first");		//unquote will change behavior!
var_dump($fixed);
	
$tmp=bar("foo");
var_dump($fixed);
$tmp=bar("foooo");
var_dump($fixed);
$tmp=bar("foooooooo");
var_dump($fixed);
$tmp=bar("fooo");
var_dump($fixed);

Expected result:
----------------
Five times the same first dump!:
array(1) {
  ["firstlevel"]=>
  array(1) {
    ["secondlevel"]=>
    string(5) "foooo"
  }
}


Actual result:
--------------
array(1) {
  ["firstlevel"]=>
  array(1) {
    ["secondlevel"]=>
    string(5) "foooo"
  }
}
array(1) {
  ["firstlevel"]=>
  string(3) "foo"
}
array(1) {
  ["firstlevel"]=>
  string(17) "someuselessstring"
}
array(1) {
  ["firstlevel"]=>
  array(1) {
    ["firstlevel"]=>
    array(1) {
      ["secondlevel"]=>
      string(9) "foooooooo"
    }
  }
}
array(1) {
  ["firstlevel"]=>
  NULL
}



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-26 13:58 UTC] pollita@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot 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 in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Mon Apr 21 02:02:11 2014 UTC