ID:               49097
 User updated by:  mkrasuski at infico dot pl
 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:

Ok about string. But what about casting to bool (same problem).


Previous Comments:
------------------------------------------------------------------------

[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)


------------------------------------------------------------------------

[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

Reply via email to