You are here: Re: Code readability vs. execution time « PHP Programming Language « IT news, forums, messages
Re: Code readability vs. execution time

Posted by Michael Fesser on 09/04/07 17:33

..oO(The Natural Philosopher)

>Michael Fesser wrote:
>>
>> The second statement simply means that the value of $int, whatever it
>> may be, evaluates to FALSE.
>>
>but what is "false", in this context?

The result after the type cast?

>Null length string? string
>containing "0" Magic value?

If you write

if ($int) {...}

then there's no other way for PHP than to cast the $int variable to a
boolean, because that's what the 'if' statement expects. The manual
explains in detail how this type casting works and which values evaluate
to FALSE:

Converting to boolean
http://www.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting

If you don't want that, then you should not rely on the automatic type
juggling, but better explain to PHP what you actually want to test for:

if ($int != 0) {...}

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

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