#32192 [Opn]: preg_grep & GLOBALS
| From: | tony2001@php.net | Date: | Fri, 04 Mar 2005 17:56:20 +0000 |
| Subject: | #32192 [Opn]: preg_grep & GLOBALS | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-74844@lists.php.net to get a copy of this message | ||
ID: 32192
Updated by: tony2001@php.net
Reported By: bolk at hitv dot ru
Status: Open
Bug Type: PCRE related
Operating System: Linux RH 9 and Windows XP
PHP Version: 5.0.3
New Comment:
bolk:
yup, this is the very same behaviour.
all elements of the target array get converted to strings, that's what
you see.
plintus:
propose your own solution instead of useless comments?
recursive references should be carefully used and current situation
looks like a user fault to me.
Previous Comments:
------------------------------------------------------------------------
[2005-03-04 18:37:12] plintus at smtp dot ru
Tony, if a bug occurs in some other situations, it's still a bug.
However, Microsoft can use this trick: "Bugs are expected behaviour in
Windows" :-)
------------------------------------------------------------------------
[2005-03-04 18:36:12] bolk at hitv dot ru
Is it "expected behaviour" too? I think no.
<?
$b = array(1,2,3);
$a = array();
$a[] = &$b;
preg_grep('/^T_/', $a);
var_dump($a);
var_dump($b);
?>
array(1) {
[0]=>
&string(5) "Array"
}
string(5) "Array"
------------------------------------------------------------------------
[2005-03-04 18:22:25] tony2001@php.net
That's because $GLOBALS contains reference to itself.
So I'd call this kinda expected behaviour.
See this code:
<?php
$a = Array();
$a[] = &$a;
preg_grep('/^T_/', $a);
var_dump($a);
?>
------------------------------------------------------------------------
[2005-03-04 17:55:03] bolk at hitv dot ru
"damages". Sorry.
------------------------------------------------------------------------
[2005-03-04 17:23:03] bolk at hitv dot ru
Description:
------------
preg_grep damage GLOBALS
Bug in PHP 4.3.10 and 5.0.3
Reproduce code:
---------------
<?
preg_grep('/^T_/', $GLOBALS);
var_dump($GLOBALS);
?>
Expected result:
----------------
array(16) {
["argv"]=>
array(1) {
[0]=>
string(5) "a.php"
}
["argc"]=>
int(1)
["HTTP_POST_VARS"]=>
array(0) {
}
["_POST"]=>
array(0) {
}
["HTTP_GET_VARS"]=>
array(0) {
}
["_GET"]=>
array(0) {
}
["HTTP_COOKIE_VARS"]=>
array(0) {
}
["_COOKIE"]=>
array(0) {
}
["HTTP_SERVER_VARS"]=>
etceteras
Actual result:
--------------
string(5) "Array"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32192&edit=1