php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44191 preg_grep messes up array index
Submitted: 2008-02-20 19:03 UTC Modified: 2008-02-20 22:16 UTC
From: admin at ifyouwantblood dot de Assigned:
Status: Closed Package: PCRE related
PHP Version: 5.2.5 OS: Windows XP
Private report: No CVE-ID: None
 [2008-02-20 19:03 UTC] admin at ifyouwantblood dot de
Description:
------------
preg_grep messes up the given array.

Reproduce code:
---------------
<?php

$array=Array(1,2,3);

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

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

while(list($key,$value)=each($array)) echo "Array: ".$value." ";

echo "<br>\n";

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

?>

Expected result:
----------------
array(3) refcount(2){ [0]=> long(1) refcount(1) [1]=> long(2) refcount(1) [2]=> long(3) refcount(1) } 
array(0) refcount(1){ } 
Array: 1 Array: 2 Array: 3 
array(3) refcount(2){ [0]=> long(1) refcount(1) [1]=> long(2) refcount(1) [2]=> long(3) refcount(1) } 

Actual result:
--------------
----PHP6 Build Jan 20 2008 18:04:22----
array(3) refcount(2){ [0]=> long(1) refcount(1) [1]=> long(2) refcount(1) [2]=> long(3) refcount(1) } 
array(0) refcount(1){ } 

array(3) refcount(2){ [0]=> long(1) refcount(1) [1]=> long(2) refcount(1) [2]=> long(3) refcount(1) } 

-----PHP5.2.5
array(3) refcount(2){ [0]=> long(1) refcount(1) [1]=> long(2) refcount(1) [2]=> long(3) refcount(1) } 
array(0) refcount(1){ } 

array(3) refcount(2){ [0]=> string(1) "1" refcount(1) [1]=> string(1) "2" refcount(1) [2]=> string(1) "3" refcount(1) } 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-20 22:16 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC