Doc->Req #76500 [Csd->ReO]: fputcsv() is ignoring the value FALSE
| From: | cmb@php.net | Date: | Tue, 19 Jun 2018 16:49:17 +0000 |
| Subject: | Doc->Req #76500 [Csd->ReO]: fputcsv() is ignoring the value FALSE | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-215791@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76500&edit=1
ID: 76500
Updated by: cmb@php.net
Reported by: thomas at landauer dot at
Summary: fputcsv() is ignoring the value FALSE
-Status: Closed
+Status: Re-Opened
-Type: Documentation Problem
+Type: Feature/Change Request
Package: Filesystem function related
Operating System: Linux Mint
PHP Version: 7.1.18
-Assigned To: cmb
+Assigned To:
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2018-06-19 16:30:14] thomas at landauer dot at
> CSV knows nothing about NULLs and booleans â it's all about
strings
Just reasoned about this some more. And I came to the conclusion that it isn't true ;-)
CSV (and
fputcsv()) does have a distinction between strings and numbers: the quotes!
true is exported as 1, not as "1". Why?? => The
only possible answer I see: Because it's casted to int (not to
string).
Well, and if you cast false to an int, what do you get? =>
0!
------------------------------------------------------------------------
[2018-06-19 15:52:31] thomas at landauer dot at
> And you won't be able to distinguish either from an empty string.
Well, an empty string is not possible in a boolean field ;-)
> In my opinion, adding yet another optional argument to fputcsv()
does more harm than good.
Why? Which harm?
------------------------------------------------------------------------
[2018-06-19 15:44:14] cmb@php.net
> So if you have a nullable boolean field in your database, this
> function becomes completely useless, since you can't tell
> null
> from false.
And you won't be able to distinguish either from an empty string.
CSV knows nothing about NULLs and booleans â it's all about
strings. You have to cater to that yourself in any way that suits
your use-case.
> But I'd suggest to add an optional argument to configure how
> false is treated - [â¦]
In my opinion, adding yet another optional argument to fputcsv()
does more harm than good. However, feel free to start the RFC
process[1]. :)
[1] <https://wiki.php.net/rfc/howto>
------------------------------------------------------------------------
[2018-06-19 15:19:45] thomas at landauer dot at
Yeah, sure (string)false === ''. But (string)null ===
'' too! So if you have a nullable boolean field in your database, this function
becomes completely useless, since you can't tell null from false.
Fixing the documentation is certainly better than nothing (haven't seen it live, though). But
I'd suggest to add an optional argument to configure how false is treated -
something like the $options constants in json_encode().
------------------------------------------------------------------------
[2018-06-19 15:03:01] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation better.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=76500
--
Edit this bug report at https://bugs.php.net/bug.php?id=76500&edit=1