php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63077 Unable to load class in output buffer handler after parse error
Submitted: 2012-09-13 00:32 UTC Modified: 2015-10-19 20:15 UTC
Votes:3
Avg. Score:3.7 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: david at grudl dot com Assigned:
Status: Closed Package: Output Control
PHP Version: 5.6.5 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: david at grudl dot com
New email:
PHP Version: OS:

 

 [2012-09-13 00:32 UTC] david at grudl dot com
Description:
------------
Due to this bug I cannot use PHP AppendIterator because it gives wrong (doubled) results. It is very hard to explain it, so there is isolated use case http://davidgrudl.com/tmp/appenditerator.zip

It affects all PHP versions.

Test script:
---------------
/*
Directory structure:

	/one
		a
		/b
			c
			d

	/two
*/


class Filter extends FilterIterator
{
	public function accept()
	{
		$this->x++;
		return $this->x > 1;
	}
}


$append = new AppendIterator();
$iterator = new RecursiveDirectoryIterator('one', RecursiveDirectoryIterator::SKIP_DOTS);
$iterator = new RecursiveIteratorIterator($iterator);
$iterator = new Filter($iterator);
$append->append($iterator);

$iterator = new RecursiveDirectoryIterator('two');
$iterator = new RecursiveIteratorIterator($iterator);
$append->append($iterator);

foreach($append as $file){
    echo $file, "\n";
}


Expected result:
----------------
Should print:
  one/b/c
  one/b/d


Actual result:
--------------
Prints:
  one/b/c
  one/b/d
  one/b/c
  one/b/d


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-13 00:48 UTC] david at grudl dot com
It is caused by append() method, because this code:

	$iterator = new RecursiveDirectoryIterator('one', RecursiveDirectoryIterator::SKIP_DOTS);
	$iterator = new RecursiveIteratorIterator($iterator);
	$iterator = new Filter($iterator);

	foreach($iterator as $file){
		echo $file, "\n";
	}

returns correctly two items, but this code:

	$iterator = new RecursiveDirectoryIterator('one', RecursiveDirectoryIterator::SKIP_DOTS);
	$iterator = new RecursiveIteratorIterator($iterator);
	$iterator = new Filter($iterator);

	$append = new AppendIterator();
	$append->append($iterator);

	foreach($iterator as $file){ // still using $iterator, not $append
		echo $file, "\n";
	}

returns 4 items.
 [2012-09-13 08:46 UTC] j dot tvr at centrum dot cz
It seems to be related to https://bugs.php.net/bug.php?id=49104 because the suggested workaround works for me.
 [2015-10-19 20:15 UTC] david at grudl dot com
-Summary: AppendIterator sometimes iterates 2 times over first iterator +Summary: Unable to load class in output buffer handler after parse error -Status: Open +Status: Closed -Package: SPL related +Package: Output Control -PHP Version: 5.4.6 +PHP Version: 5.6.5
 [2015-10-19 20:15 UTC] david at grudl dot com
Fixed in PHP >= 5.5.23 and PHP >= 5.6.7
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC