Bug #60391 [Opn->Bgs]: fputcsv() returns NULL if first argument is not resource
| From: | salathe@php.net | Date: | Sat, 03 Dec 2011 19:21:54 +0000 |
| Subject: | Bug #60391 [Opn->Bgs]: fputcsv() returns NULL if first argument is not resource | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-7518@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60391&edit=1
ID: 60391
Updated by: salathe@php.net
Reported by: ninzya at inbox dot lv
Summary: fputcsv() returns NULL if first argument is not
resource
-Status: Open
+Status: Bogus
Type: Bug
Package: Documentation problem
Operating System: Windows 7
PHP Version: 5.4.0RC2
Block user comment: N
Private report: N
New Comment:
See the following note on the "Internal (built-in) functions" page [1].
"Note: If the parameters given to a function are not what it expects, such as
passing an array where a string is expected, the return value of the function is
undefined. In this case it will likely return NULL but this is just a
convention, and cannot be relied upon."
By convention, we do not mention this "undefined" behaviour (NULL for the vast
majority of functions) on bad arguments in each and every function's "Return
Values" section. See also, GIGO [2].
[1] http://php.net/manual/en/functions.internal.php
[2] http://en.wikipedia.org/wiki/Garbage_in,_garbage_out
Previous Comments:
------------------------------------------------------------------------
[2011-12-03 16:24:45] ninzya at inbox dot lv
Documentation does not cover the case you have described: "Returns the length of
the written string or FALSE on failure" does not mean "NULL is returned when
zend_parse_parameters returns FAILURE, meaning the types of
the parameters didn't match the function signature".
So from my point of view the problem is either in the code or in the
documentation.
------------------------------------------------------------------------
[2011-12-03 03:08:39] me at ktamura dot com
NULL is returned when zend_parse_parameters returns FAILURE, meaning the types of
the parameters didn't match the function signature. This is the behavior for many
other buildin functions such as flock, realpath, etc. I don't think this is a bug.
------------------------------------------------------------------------
[2011-11-26 08:00:46] ninzya at inbox dot lv
Description:
------------
PHP documentation on fputcsv() [http://www.php.net/manual/en/function.fputcsv.php]
says (quote):
"Returns the length of the written string or FALSE on failure".
This is not true if fputcsv() gets a non-resource variable as it's first argument.
In this case it returns NULL.
Test script:
---------------
$arg =true;
//$arg =false;
//$arg =1;
//$arg =null;
//$arg =array();
//$arg =new stdClass;
var_dump( fputcsv( $arg, array( 'x', 'y', 'z')));
Expected result:
----------------
bool(false)
Actual result:
--------------
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60391&edit=1