Bug #76500 [Com]: fputcsv() is ignoring the value FALSE
| From: | haseeb dot basil at gmail dot com | Date: | Tue, 19 Jun 2018 14:41:39 +0000 |
| Subject: | Bug #76500 [Com]: fputcsv() is ignoring the value FALSE | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-215789@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
Comment by: haseeb dot basil at gmail dot com
Reported by: thomas at landauer dot at
Summary: fputcsv() is ignoring the value FALSE
Status: Open
Type: Bug
Package: Filesystem function related
Operating System: Linux Mint
PHP Version: 7.1.18
Block user comment: N
Private report: N
New Comment:
This doesn't sound like a bug, it is possible for false to be interpreted as null rather than
0. You can probably do something like this to get 0(adjust according to your actual code):
Script:
---------------------
$data = array('name'=>'foo', 'active'=> (int)false);
$f = fopen('php://memory', 'r+');
fputcsv($f, $data);
rewind($f);
echo stream_get_contents($f);
Result:
--------------------------
foo,0
Previous Comments:
------------------------------------------------------------------------
[2018-06-19 14:32:15] thomas at landauer dot at
Description:
------------
When a data value is
false, fputcsv() just omits it - instead of exporting it as
0.
Test script:
---------------
$data = array('name'=>'foo', 'active'=>false);
$f = fopen('php://memory', 'r+');
fputcsv($f, $data);
rewind($f);
echo stream_get_contents($f);
Expected result:
----------------
foo,0
Actual result:
--------------
foo,
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76500&edit=1