php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52163 SplFileObject::fgetss() fails due to parameter that can't be set
Submitted: 2010-06-23 21:16 UTC Modified: 2010-06-25 01:11 UTC
From: v-ryanbi at microsoft dot com Assigned: felipe
Status: Closed Package: SPL related
PHP Version: 5.2.14RC1 OS: Windows 7
Private report: No CVE-ID:
 [2010-06-23 21:16 UTC] v-ryanbi at microsoft dot com
Description:
------------
When calling SplFileObject::ffgetss() in 5.2.x (including the 5.2.14 RC1), a 
warning is thrown and the cursor is *not* advanced. Since this would typically be 
used in a while(!$fileObj->eof()) loop, it can result in an infinite loop.

The complaint thrown in the warning is that the Length parameter must be greater 
than 0. While Length is a valid parameter in the global fgetss function, the SPL 
version of this function only accepts one parameter, and that is for accepted 
tags.

Test script:
---------------
<?php
$str = <<<EOD
<html><body>
 <p>Welcome! Today is the <?php echo(date('jS')); ?> of <?= date('F'); ?>.</p>
</body></html>
Text outside of the HTML block.
EOD;

$filePath="filename.php";
file_put_contents($filePath, $str);


$fileObject = new SplFileObject($filePath);
while (!$fileObject->eof()) {
    echo $fileObject->fgetss('body');
}
?>

Expected result:
----------------
 Welcome! Today is the  of .

Text outside of the HTML block.

Actual result:
--------------
Warning: fgetss(): Length parameter must be greater than 0 in 
C:\fgetssBug\fgetss_basic.php on line 13

Warning: fgetss(): Length parameter must be greater than 0 in 
C:\fgetssBug\fgetss_basic.php on line 13

Warning: fgetss(): Length parameter must be greater than 0 in 
C:\fgetssBug\fgetss_basic.php on line 13

Warning: fgetss(): Length parameter must be greater than 0 in 
C:\fgetssBug\fgetss_basic.php on line 13

Warning: fgetss(): Length parameter must be greater than 0 in 
C:\fgetssBug\fgetss_basic.php on line 13

Warning: fgetss(): Length parameter must be greater than 0 in 
C:\fgetssBug\fgetss_basic.php on line 13

Warning: fgetss(): Length parameter must be greater than 0 in 
C:\fgetssBug\fgetss_basic.php on line 13

Warning: fgetss(): Length parameter must be greater than 0 in 
C:\fgetssBug\fgetss_basic.php on line 13

... and on to infinity.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-23 21:18 UTC] v-ryanbi at microsoft dot com
-Summary: fails due to parameter that can't be set +Summary: SplFileObject::fgetss() fails due to parameter that can't be set
 [2010-06-23 21:18 UTC] v-ryanbi at microsoft dot com
Argh. typo. In the description it should be SplFileObject::fgetss().
 [2010-06-25 01:10 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=300741
Log: - Fixed bug #52163 (SplFileObject::fgetss() fails due to parameter that can't be set) [already fixed on other branches]
 [2010-06-25 01:11 UTC] felipe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: felipe
 [2010-06-25 01:11 UTC] felipe@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 07:02:14 2014 UTC