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 Toby A Inkster on 01/06/08 23:19

A Bit Narked wrote:

> And yet you can echo true. The output is '1'.

No -- you can't echo a boolean in PHP. Why you try, the boolean is
implicitly cast to a string.

This:

echo $bool;

is actually executed as if you coded this:

echo (string)$bool;

If you look up the manual on type casting, you'll find that FALSE is cast
to an empty string, and TRUE is cast to a non-empty string.

If you cast to an integer instead of a string, then you'll find that FALSE
is cast to 0, which seems to be what you want.

echo (int)FALSE;

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 7 days, 10:29.]

dhyana.pl/0.3
http://tobyinkster.co.uk/blog/2008/01/06/dhyana/

 

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

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