note 80254 added to language.types.boolean
| From: | Anonymous at osu1 dot php dot net | Date: | Sun, 06 Jan 2008 15:05:52 +0000 |
| Subject: | note 80254 added to language.types.boolean | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-134895@lists.php.net to get a copy of this message | ||
Note that the symbolic constants TRUE and FALSE are treated differently. I was told that this is a
feature, not a bug.
echo false ;
echo (false) ;
echo false+false ;
echo (false+false) ;
echo intval(false) ;
echo '"'.false.'"' ;
echo true ;
echo (true) ;
echo true+true ;
echo (true+true) ;
echo intval(true) ;
echo '"'.true.'"' ;
should produce
00000"0"11221"1"
but instead produces
000""11221"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.
The whole idea of symbolic constants is that the underlying value *always* replaces them during
translation, and thus anywhere you would otherwise have to use some obscure "magic number"
such as 191, you can use a symbolic constant that makes sense, such as TOTAL_NATIONS.
Exactly what php gets out of breaking this rule was not explained to me.
----
Server IP: 209.41.74.194
Probable Submitter: 71.123.74.100
----
Manual Page -- http://www.php.net/manual/en/language.types.boolean.php
Edit -- https://master.php.net/note/edit/80254
Del: integrated -- https://master.php.net/note/delete/80254/integrated
Del: useless -- https://master.php.net/note/delete/80254/useless
Del: bad code -- https://master.php.net/note/delete/80254/bad+code
Del: spam -- https://master.php.net/note/delete/80254/spam
Del: non-english -- https://master.php.net/note/delete/80254/non-english
Del: in docs -- https://master.php.net/note/delete/80254/in+docs
Del: other reasons-- https://master.php.net/note/delete/80254
Reject -- https://master.php.net/note/reject/80254
Search -- https://master.php.net/manage/user-notes.php