ID:               45788
 User updated by:  steven at realestatewebmasters dot com
 Reported By:      steven at realestatewebmasters dot com
 Status:           Bogus
 Bug Type:         Filesystem function related
 Operating System: Linux
 PHP Version:      5.2.6
 New Comment:

I accept that it should not throw an error.

I do think it should act like all the other file functions (like
fgetc() ) that will return false on invalid parameters.

At the very least could the documentation for this function be updated?
The current example:

$handle = fopen("test.csv", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {

will cause an infinite loop if you fail to open the file.


Previous Comments:
------------------------------------------------------------------------

[2008-08-12 14:24:14] [EMAIL PROTECTED]

Invalid parameter does not cause fatal error in any PHP function. And
when an invalid parameter is passed, all functions using the new (more
consistent) parameter parsing also return NULL. No bug here.

------------------------------------------------------------------------

[2008-08-11 18:36:49] steven at realestatewebmasters dot com

Description:
------------
fgetcsv returns null if passed false as the handle. This should cause
and error instead of a warning and cause the function to return false.

Reproduce code:
---------------
<?php

$handle = fopen("foo","r");

var_dump($data = fgetcsv($handle,0,",",'"'));

while (($data = fgetcsv($handle,0,",",'"')) !== false) {
        echo 'test';
}

?>

Expected result:
----------------
Warning: fopen(foo): failed to open stream: No such file or directory
in /home/sbarre85/test.php on line 3

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in
/home/sbarre85/test.php on line 5
bool(false)

Error: fgetcsv() expects parameter 1 to be resource, boolean given in
/home/sbarre85/test.php on line 7

Actual result:
--------------
Warning: fopen(foo): failed to open stream: No such file or directory
in /home/sbarre85/test.php on line 3

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in
/home/sbarre85/test.php on line 5
NULL

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in
/home/sbarre85/test.php on line 7
test

.. looping infinitly


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=45788&edit=1

Reply via email to