Bug #60391 [Com]: fputcsv() returns NULL if first argument is not resource
| From: | anon at anon dot anon | Date: | Sun, 04 Dec 2011 16:14:48 +0000 |
| Subject: | Bug #60391 [Com]: fputcsv() returns NULL if first argument is not resource | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-7555@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
Comment by: anon at anon dot anon
Reported by: ninzya at inbox dot lv
Summary: fputcsv() returns NULL if first argument is not
resource
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:
>I think I'm starting to think about giving up PHP and move to something more
life-ready (read - "enterprise-ready").
Ditto. This is extremely poor behavior for a programming language to have, but it's just
another day for PHP. :(
Previous Comments:
------------------------------------------------------------------------
[2011-12-03 22:23:23] ninzya at inbox dot lv
Oh, that's cute. I've been developing apps with PHP for 5+ years and now this is
first hearing of such "built in" feature for me. Really nice. Good docs. Very
intuitive.
I think I'm starting to think about giving up PHP and move to something more
life-ready (read - "enterprise-ready").
------------------------------------------------------------------------
[2011-12-03 19:21:54] salathe@php.net
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
------------------------------------------------------------------------
[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