Doc #76500 [Com]: fputcsv() is ignoring the value FALSE

From: Date: Tue, 19 Jun 2018 15:19:46 +0000
Subject: Doc #76500 [Com]: fputcsv() is ignoring the value FALSE
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-15801@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: thomas at landauer dot at Reported by: thomas at landauer dot at Summary: fputcsv() is ignoring the value FALSE Status: Closed Type: Documentation Problem Package: Filesystem function related Operating System: Linux Mint PHP Version: 7.1.18 Assigned To: cmb Block user comment: N Private report: N New Comment: 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(). Previous Comments: ------------------------------------------------------------------------ [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. ------------------------------------------------------------------------ [2018-06-19 15:02:37] cmb@php.net Automatic comment from SVN on behalf of cmb Revision: http://svn.php.net/viewvc/?view=revision&revision=345171 Log: Fix #76500: fputcsv() is ignoring the value FALSE ------------------------------------------------------------------------ [2018-06-19 14:57:12] cmb@php.net Indeed, this is not a bug, since (string)false === ''. The docs could be improved in this regard, though. ------------------------------------------------------------------------ [2018-06-19 14:41:36] haseeb dot basil at gmail dot com 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 ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#15801) next »