ID:               26508
 Updated by:       [EMAIL PROTECTED]
 Reported By:      putaso at nospam dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         PCRE related
 Operating System: Windows 2000
 PHP Version:      4.3.3
 New Comment:

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".


Previous Comments:
------------------------------------------------------------------------

[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

Reply via email to