From: putaso at nospam dot com Operating system: Windows 2000 PHP version: 4.3.3 PHP Bug Type: PCRE related Bug description: preg_replace() misbehavior with multidimensional arrays as "subject" paramenter
Description: ------------ <?php /* preg_replace() misbehavior. Treats Multidimensinal arrays in "subject" in a really weird way. */ class object {}; $alpha = new object; $alpha->beta = "alpha-beta"; $alpha->gama->x = "hola"; $array = array("a" => "abc", "azw", array("a", "b", array("af")), $alpha->beta, $alpha->gama ); print_r (preg_replace("/[a|e|i|o|u]/", "#", $array)); /* and this is what i get: Array ( [a] => #bc [0] => #zw [1] => Arr#y [2] => #lph#-b#t# [3] => Obj#ct ) Is is correct that i get an array element called "Arr#y" and Obj#ct?? shouldn't preg_replace go through the arrays recursively? The manual is not very clear about that: "If subject is an array, then the search and replace is performed on every entry of subject , and the return value is an array as well." anyways... I don't think that if the function finds an array or an object, treats it as string "Array" and string "Object", */ ?> Reproduce code: --------------- <?php class object {}; $alpha = new object; $alpha->beta = "alpha-beta"; $alpha->gama->x = "hola"; $array = array("a" => "abc", "azw", array("a", "b", array("af")), $alpha->beta, $alpha->gama ); print_r (preg_replace("/[a|e|i|o|u]/", "#", $array)); ?> Expected result: ---------------- Array ( [a] => #bc [0] => #zw [1] => Array ( [0] => # [1] => b [2] => Array ( [0] => #f ) ) [2] => #lph#-b#t# [3] => stdClass Object ( [x] => hol# ) ) Actual result: -------------- Array ( [a] => #bc [0] => #zw [1] => Arr#y [2] => #lph#-b#t# [3] => Obj#ct ) -- Edit bug report at http://bugs.php.net/?id=26508&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26508&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26508&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=26508&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=26508&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=26508&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=26508&r=needscript Try newer version: http://bugs.php.net/fix.php?id=26508&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=26508&r=support Expected behavior: http://bugs.php.net/fix.php?id=26508&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=26508&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=26508&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=26508&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26508&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=26508&r=dst IIS Stability: http://bugs.php.net/fix.php?id=26508&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=26508&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=26508&r=float