You are here: Re: TRUE and FALSE are treated differently « PHP Programming Language « IT news, forums, messages
Re: TRUE and FALSE are treated differently

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация