Bug #70608 [Com]: Echo dosn't print false
| From: | php at sogetthis dot com | Date: | Wed, 30 Sep 2015 12:59:53 +0000 |
| Subject: | Bug #70608 [Com]: Echo dosn't print false | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-196316@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70608&edit=1
ID: 70608
Comment by: php at sogetthis dot com
Reported by: khaweronline at gmail dot com
Summary: Echo dosn't print false
Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: ALL OS
PHP Version: 5.6.13
Block user comment: N
Private report: N
New Comment:
From the documentation: "A boolean TRUE value is converted to the string "1". Boolean
FALSE is converted to "" (the empty string)."
http://php.net/manual/en/language.types.string.php#language.types.string.casting
You could do:
echo $a == $b ? '1' : '0';
Previous Comments:
------------------------------------------------------------------------
[2015-09-30 12:58:19] bwoebi@php.net
var_dump((string) false);
prints string(0) "", as the string representation of false is actually an empty string.
Hence echoing it actually prints nothing.
------------------------------------------------------------------------
[2015-09-30 12:48:35] khaweronline at gmail dot com
Description:
------------
<?php
$a = 12;
$b = 15;
echo $a==$b; // This should output false or 0, but it didn't output anything
var_dump($a==$b); /* This will output Boolean false. This is just for reference that the value is
false */
// We can also assign it to a variable then echo and var_dump
$c = $a==$b;
echo $c; // This should output false or 0, but it didn't output anything
var_dump($c); /* This will output Boolean false. This is just for reference that the value is false
*/
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70608&edit=1