#49097 [Opn->Bgs]: Boolean type casting print problem
| From: | scottmac@php.net | Date: | Wed, 29 Jul 2009 11:38:32 +0000 |
| Subject: | #49097 [Opn->Bgs]: Boolean type casting print problem | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-140424@lists.php.net to get a copy of this message | ||
ID: 49097
Updated by: scottmac@php.net
Reported By: mkrasuski at infico dot pl
-Status: Open
+Status: Bogus
Bug Type: Output Control
Operating System: Windows 7/XP
PHP Version: 5.3.0
New Comment:
All works here, the cast of a bool to string is "".
<?php
$b = 2;
var_dump((!$b));
echo PHP_EOL;
var_dump((string) !$b);
echo PHP_EOL;
var_dump((bool) !$b);
echo PHP_EOL;
var_dump((int) !$b);
echo PHP_EOL;
var_dump(((bool) $b));
echo PHP_EOL;
var_dump(!$b);
Output:
bool(false)
string(0) ""
bool(false)
int(0)
bool(true)
bool(false)
Previous Comments:
------------------------------------------------------------------------
[2009-07-29 10:31:21] mkrasuski at infico dot pl
Description:
------------
I think, there's a problem with type casting -- to be more specific,
with boolean casting.
When I was trying to print result of the condition (should be true, or
false) I received some unexpected output.
Reproduce code:
---------------
<?php
$b = 2;
echo 'Should be false: ' . (!$b);
echo '<br />';
echo (string) !$b;
echo '<br />';
echo (bool) !$b;
echo '<br />';
echo (int) !$b;
echo '<br />';
echo 'Should be true: ' . ((bool) $b);
echo '<br />';
var_dump(!$b);
?>
Expected result:
----------------
Should be false: false
false // or 0?
false
0
Should be true: true
bool(false)
Actual result:
--------------
Should be false:
0
Should be true: 1
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49097&edit=1