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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 22:01:33 2025 UTC