php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33609 function fgets returns error when optional parameter not passed
Submitted: 2005-07-07 22:32 UTC Modified: 2005-07-08 01:49 UTC
From: php at yvanrodrigues dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.11 OS: Windows 2000/XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at yvanrodrigues dot com
New email:
PHP Version: OS:

 

 [2005-07-07 22:32 UTC] php at yvanrodrigues dot com
Description:
------------
function fgets is documented as:

string fgets ( resource handle [, int length] )

however if called with one argument it shows warning:

Warning:  Wrong parameter count for fread() in  scriptname.php


This has been reported in previous versions (eg bug 15480) and fixed. I suspect this snuck back in.

The docs say the optional parameter has been in place since 4.2.0 I believe

Reproduce code:
---------------
		for($a=0; !feof($fp); $a++) {
			$instring = fread($fp);
			$todayarray[$a] = array();
			$todayarray[$a]['Course Code'] = trim(substr($instring, 0, 12));
			$todayarray[$a]['Section']     = trim(substr($instring, 12, 13));
			$todayarray[$a]['Cap']         = trim(substr($instring, 25, 4));
			$todayarray[$a]['Enrollment']  = trim(substr($instring, 29, 4));
			$todayarray[$a]['Professor']   = trim(substr($instring, 33));
			break;
		}


Expected result:
----------------
I expect a string to be returned consisting of a line from the file starting at position 0 of the row and ending when the newline \r\n is reached.

Actual result:
--------------
php displays an error and dies

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-07 22:38 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

fread() & fgets() are 2 different functions.
 [2005-07-08 01:49 UTC] php at yvanrodrigues dot com
damn, my mind must have been elsewhere when I wrote that line of code. Sorry for the crazy-talk
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 01 09:01:31 2024 UTC