Bug #63077 [Opn->Csd]: Unable to load class in output buffer handler after parse error
| From: | david at grudl dot com | Date: | Mon, 19 Oct 2015 20:15:09 +0000 |
| Subject: | Bug #63077 [Opn->Csd]: Unable to load class in output buffer handler after parse error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-196689@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63077&edit=1
ID: 63077
User updated by: david at grudl dot com
Reported by: 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
Type: Bug
-Package: SPL related
+Package: Output Control
-PHP Version: 5.4.6
+PHP Version: 5.6.5
Block user comment: N
Private report: N
New Comment:
Fixed in PHP >= 5.5.23 and PHP >= 5.6.7
Previous Comments:
------------------------------------------------------------------------
[2012-09-13 08:46:48] 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.
------------------------------------------------------------------------
[2012-09-13 00:48:19] 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 00:32:41] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63077&edit=1