php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63616 iterator_count loves SplFileObject too much (endless)
Submitted: 2012-11-26 21:43 UTC Modified: 2013-09-12 14:13 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: hanskrentel at yahoo dot de Assigned: helly (profile)
Status: Duplicate Package: SPL related
PHP Version: 5.4.9 OS: Windows
Private report: No CVE-ID: None
 [2012-11-26 21:43 UTC] hanskrentel at yahoo dot de
Description:
------------
For some reason not clear to me, using iterator_count with the iterator interface 
of SplFileObject (as well with SplTempFileObject) results in an endless running 
script.

Test script:
---------------
<?php
$test = new SplFileObject("data://text/plain,1\n2");
$test->setFlags(SplFileObject::DROP_NEW_LINE);
echo "Values: [", implode(', ', iterator_to_array($test)),
     "]\nCount: ", iterator_count($test), "\n";
?>

-- OR --

<?php
$test = new SplTempFileObject();
$test->setFlags(SplTempFileObject::DROP_NEW_LINE);
$test->fwrite("1\n2");
echo "Values: [", implode(', ', iterator_to_array($test)),
     "]\nCount: ", iterator_count($test), "\n";
?>

Expected result:
----------------
Values: [1, 2]
Count: 2

Actual result:
--------------
Values: [1, 2]
Count: 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-27 08:39 UTC] laruence@php.net
helly, do you have time to look at this? seems memory stream doesn't handle the 
eof in this situation.

thanks ;)
 [2012-11-27 08:39 UTC] laruence@php.net
-Assigned To: +Assigned To: helly
 [2013-09-12 14:13 UTC] nikic@php.net
-Status: Assigned +Status: Duplicate
 [2013-09-12 14:13 UTC] nikic@php.net
This has the same underlying issue as https://bugs.php.net/bug.php?id=65600. SplFileObject does not advance to the next line unless current() was called.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 20:01:29 2024 UTC