|
Posted by Michael Fesser on 01/06/08 18:53
..oO(A Bit Narked)
>Can someone explain the rationale - if there is one - behind
>treating the constants TRUE and FALSE differently?
>
>echo false ;
>echo false+false ;
>echo intval(false) ;
>echo '"'.false.'"' ;
>
>echo true ;
>echo true+true ;
>echo intval(true) ;
>echo '"'.true.'"' ;
>
>should produce
>
>000"0"121"1"
>
>but instead produces
>
>00""121"1"
>
>In other words, the only way to output the underlying zero or use
>it in a string is to use 'false+false' or pass it through
>intval(). No such tricks are required to get at the 1 that
>underlies true.
First: The internal values of the constants FALSE and TRUE are _not_ the
integers 0 and 1, but the two possible values of the type 'bool':
var_dump(constant('FALSE'));
bool(false)
var_dump(constant('TRUE'));
bool(true)
Second: If you print out a boolean, its value is automatically converted
to a string. How and why this is done is described in the manual:
| A boolean TRUE value is converted to the string "1", the FALSE value
| is represented as "" (empty string). This way you can convert back and
| forth between boolean and string values.
Micha
Navigation:
[Reply to this message]
|