|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-12-03 09:11 UTC] derick@php.net
[2003-12-03 09:32 UTC] putaso at nospam dot com
[2003-12-03 09:38 UTC] derick@php.net
[2003-12-03 13:48 UTC] putaso at ospam dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 21:00:02 2025 UTC |
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 )