ID: 49097
Updated by: [email protected]
Reported By: mkrasuski at infico dot pl
Status: Bogus
Bug Type: Output Control
Operating System: Windows 7/XP
PHP Version: 5.3.0
New Comment:
You need to be able to get consistent behavior regardless of the cast,
not everyone is just printing the output.
$false = false;
if ((string)$false)) { die("oops"); }
If the typecast made it return "false" then you'd see the oops here.
Previous Comments:
------------------------------------------------------------------------
[2009-07-29 12:33:19] mkrasuski at infico dot pl
One more thing.
> false has to be an empty string to correctly evaluate to false.
> No bug here.
May I ask, why? When casting '153 foo' to int you get 153. Why, when
casting 'false' (or 'FALSE', whatever) you get 1 (true), not 0 (false)?
PHP is a script language, it should the difference, IMO.)
------------------------------------------------------------------------
[2009-07-29 12:24:15] mkrasuski at infico dot pl
Ok about string. But what about casting to bool (same problem).)
------------------------------------------------------------------------
[2009-07-29 11:56:20] [email protected]
false has to be an empty string to correctly evaluate to false. No bug
here.
------------------------------------------------------------------------
[2009-07-29 11:51:24] mkrasuski at infico dot pl
You missunderstood me. The cast of a bool(false) is "" but cast of a
bool(true) is "1". IMO it should be "false" and "true", or, at least "0"
and "1".)
------------------------------------------------------------------------
[2009-07-29 11:38:31] [email protected]
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)
------------------------------------------------------------------------
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
http://bugs.php.net/49097
--
Edit this bug report at http://bugs.php.net/?id=49097&edit=1