|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-08-11 18:36 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 15:00:01 2025 UTC |
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.