From:             admin at ifyouwantblood dot de
Operating system: 
PHP version:      5.2.6
PHP Bug Type:     PCRE related
Bug description:  preg_grep and array index - follow up on #44191

Description:
------------
this is a follow up on bug #44191. that was fixed, but everything inside
the array is now converted to a string. as i understand it, the search
array shouldn't change at all, so i think this is a bug. please note that
with objects without a __toString() method, this of course leads to a fatal
error.

another thing is, preg_grep issues a warning if you give it an object
instead of converting the object to an array (like other function like
array_flip() do)

addtionally a question: how should preg_grep react on multi-dimensional
arrays anyways? convert them to a string and try to match the pattern? go
through every level and return a multi-dimensional array? issue a warning?

Reproduce code:
---------------
$array=Array("1",2,3,1.1,FALSE,NULL,Array());

var_dump($array); echo "<br>\n";

var_dump(preg_grep('/asdf/',$array)); echo "<br>\n";

var_dump($array); echo "<br>\n";

var_dump(preg_grep('/asdf/',new stdClass)); echo "<br>\n";

Expected result:
----------------
array(8) { [0]=> string(1) "1" [1]=> int(2) [2]=> int(3) [3]=> float(1.1)
[4]=> bool(false) [5]=> NULL [6]=> array(0) { } [7]=> object(stdClass)#8
(0) { } } 

array(0) { }

array(8) { [0]=> string(1) "1" [1]=> int(2) [2]=> int(3) [3]=> float(1.1)
[4]=> bool(false) [5]=> NULL [6]=> array(0) { } }  

array(0) { }

Actual result:
--------------
array(7) { [0]=> string(1) "1" [1]=> int(2) [2]=> int(3) [3]=> float(1.1)
[4]=> bool(false) [5]=> NULL [6]=> array(0) { } } 

Notice: Array to string conversion in D:\_projects\preg_grep.php

array(0) { } 

array(7) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3"
[3]=> string(3) "1.1" [4]=> string(0) "" [5]=> string(0) "" [6]=> string(5)
"Array" }

Warning: preg_grep() expects parameter 2 to be array, object given in
D:\_projects\cms\admin\data\classes\class.article.php on line 13
NULL 



-- 
Edit bug report at http://bugs.php.net/?id=44925&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44925&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44925&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44925&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=44925&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=44925&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=44925&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=44925&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=44925&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=44925&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=44925&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=44925&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=44925&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=44925&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=44925&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=44925&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=44925&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=44925&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44925&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=44925&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=44925&r=mysqlcfg

Reply via email to