#25671 [NEW]: nested array with str_replace

From: Date: Fri, 26 Sep 2003 15:51:37 +0000
Subject: #25671 [NEW]: nested array with str_replace
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-48153@lists.php.net to get a copy of this message
From: ivan dot lamouret at caramail dot com Operating system: cobalt linux 6.4 PHP version: 4.3.2 PHP Bug Type: Unknown/Other Function Bug description: nested array with str_replace 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 } -- Edit bug report at http://bugs.php.net/?id=25671&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=25671&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=25671&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=25671&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=25671&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=25671&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=25671&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=25671&r=support Expected behavior: http://bugs.php.net/fix.php?id=25671&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=25671&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=25671&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=25671&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25671&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=25671&r=dst IIS Stability: http://bugs.php.net/fix.php?id=25671&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=25671&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=25671&r=float

« previous php.bugs (#48153) next »