#32192 [Com]: preg_grep & GLOBALS

From: Date: Fri, 04 Mar 2005 17:37:13 +0000
Subject: #32192 [Com]: preg_grep & GLOBALS
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-74842@lists.php.net to get a copy of this message
ID: 32192 Comment by: plintus at smtp dot ru 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: 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" :-) Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#74842) next »