#26508 [Bgs]: preg_replace() misbehavior with multidimensional arrays as "subject" paramenter
| From: | putaso at nospam dot com | Date: | Wed, 03 Dec 2003 14:32:02 +0000 |
| Subject: | #26508 [Bgs]: preg_replace() misbehavior with multidimensional arrays as "subject" paramenter | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-51622@lists.php.net to get a copy of this message | ||
ID: 26508
User updated by: putaso at nospam dot com
Reported By: putaso at nospam dot com
Status: Bogus
Bug Type: PCRE related
Operating System: Windows 2000
PHP Version: 4.3.3
New Comment:
Shouldn't it be more clear in the manual?
anyways.. i don't think you should get "Array" and "object" strings
then if now multidimensional arrays are supported.
Should I create a new bug as a Documentation Bug, or something like
that?
thanks to you for taking the time for replying.
Previous Comments:
------------------------------------------------------------------------
[2003-12-03 09:11:33] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
preg_replace doesn\'t do multidimensional arrays so arays get converted
to \"Array\" and objects to \"Object\".
------------------------------------------------------------------------
[2003-12-03 09:04:18] putaso at nospam dot com
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 this bug report at http://bugs.php.net/?id=26508&edit=1