php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68004 SplTempFileObject and LimitIterator don't come along
Submitted: 2014-09-11 09:41 UTC Modified: 2021-07-20 22:40 UTC
From: doldev at snowgarden dot ch Assigned: cmb (profile)
Status: Closed Package: SPL related
PHP Version: 5.6.0 OS: Linux
Private report: No CVE-ID: None
 [2014-09-11 09:41 UTC] doldev at snowgarden dot ch
Description:
------------
If SplTempFileObject used with the LimitIterator in some cases it behave wrong.

This might be related to #65600 . Even though if switching to an SplFileObject fixes the problem with the same input.

Test script:
---------------
<?php

$content = <<<'EOF'
Line 1
Line 2
Line 3
Line 4
EOF;

$tmpCsvFile = new SplTempFileObject();
$tmpCsvFile->fwrite($content);

$iterator = new CallbackFilterIterator($tmpCsvFile, function ($row) {
    return true;
});

echo 'Limit 1: ', iterator_count(new LimitIterator($iterator, 2)), ' ', iterator_count(new LimitIterator($tmpCsvFile, 2)), "\n";
echo 'Limit 2: ', iterator_count(new LimitIterator($iterator, 3)), ' ', iterator_count(new LimitIterator($tmpCsvFile, 3)), "\n";

Expected result:
----------------
Limit 2: 2 2
Limit 3: 1 1

Actual result:
--------------
Limit 2: 2 2
Limit 3: 1 0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-09-11 09:46 UTC] doldev at snowgarden dot ch
Example: http://3v4l.org/AJBR9

Don't worry about the output of HHVM -> it has been fixed recently https://github.com/facebook/hhvm/issues/2993
 [2021-07-20 22:14 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-07-20 22:14 UTC] cmb@php.net
This is fixed[1] as of PHP 8.0.0.

[1] <https://github.com/php/php-src/commit/f1d11c118dfdc911f2f33babb9b2cba8bf5acb67>.
 [2021-07-20 22:40 UTC] cmb@php.net
Correction: fixed as of PHP 8.0.1 only.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 12:01:28 2024 UTC