|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50579 RegexIterator::REPLACE doesn't work
Submitted: 2009-12-26 13:18 UTC Modified: 2010-11-08 21:27 UTC
Avg. Score:4.0 ± 1.0
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:4 (100.0%)
From: team at fazend dot com Assigned: felipe
Status: Closed Package: SPL related
PHP Version: 5.*, 6 OS: *
Private report: No CVE-ID:
 [2009-12-26 13:18 UTC] team at fazend dot com
RegexIterator::REPLACE doesn't work as it is supposed to do. The code 
example attached should return something, but it returns nothing.

Reproduce code:
$i = new RegexIterator(
  new ArrayIterator(array(

foreach ($i as $name=>$value)
  echo $name . '=>' . $value . "\n";

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-29 15:04 UTC]
Seems like this thing never got finished. There aren't any tests for it either..
 [2010-07-11 05:31 UTC] jinmoku at hotmail dot com
In original doc (, RegexIterator::REPLACE wait for "replacement" property, but it's doesn't exist in __construct and properties.

In ext/spl replacement exist as public property but not in __construct method, so I try to extends it like this

public function __construct($iterator, $regex, $mode = 0, $flags = 0, $preg_flags = 0)
    parent::__construct($iterator, $regex, $mode, $flags, $preg_flags);
    $this->replacement = '$1';					

but nothing append to :(
 [2010-11-06 01:09 UTC]
Automatic comment from SVN on behalf of felipe
Log: - Fixed bug #50579 (RegexIterator::REPLACE doesn't work)
 [2010-11-06 01:17 UTC]
-Status: Verified +Status: Closed -Assigned To: +Assigned To: felipe
 [2010-11-06 01:18 UTC]
This bug has been fixed in SVN.

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

 [2010-11-08 13:46 UTC] jinmoku at hotmail dot com
Hi, i saw the test file (bug50579.phpt), it's strange to put the replacement property on the iterator parameter insteed the Regexiterator instance, imagine i've this follow code :

class foo extends ArrayIterator {
	public function __construct( ) {
		'replacement' => 'replacement'), ArrayIterator::ARRAY_AS_PROPS);
		$this->replacement = '[$1]';

if a would read $h->replacement, i've '[$1]' insteed 'replacement'.

it's more logical to do :

$i = new RegexIterator($h, '/^test(.*)/', RegexIterator::REPLACE);
$i->replacement = '[$0]';

or maybe make a methode :

 [2010-11-08 21:27 UTC]
You are right, I've fixed the property issue.

Thanks for reviewing/testing/reporting! :)
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Sat Nov 28 02:01:31 2015 UTC