News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Felix Geisendorfer's Blog:
False == 0, or not?
August 14, 2007 @ 08:45:00

Felix Geisendorfer has come across something interesting in his coding - an issue where false might not be false in the right situation.

So far I've always thought false would evaluate to 0 when used in a computational context. Turns out that this isn't always the case.

His code example tries to check is a false value is greater than or equal to a negative number. The result, however (despite the thinking that false is a zero value) turns out to be false.

I randomly stumbled upon this when arguing with Mariano today if setting Model::recursive to 'false' has the same effect as setting it to '-1'. Turns out that cake uses a statement like this: if ($recursive > -1) in the core which in turn makes -1 and false do exactly the same thing.
0 comments voice your opinion now!
false zero evaluate compare negative false zero evaluate compare negative


blog comments powered by Disqus

Similar Posts

Udemy Blog: Code Wars: PHP vs Ruby vs Python - Who Reigns Supreme [Infographic]

TechToolBlog: Ruby, PHP, ASP.NET Job Comparison

SitePoint: WordPress v Joomla: Support and Community

Mike Bernat's Blog: PHP Cookies vs Sessions - The Breakdown

A Cloudy Place: PHPFog and Pagoda Box: A Look at PHP Platforms


Community Events

Don't see your event here?
Let us know!


conference podcast library extension interview framework laravel voicesoftheelephpant introduction wordpress api community release language unittest series psr7 laravel5 opinion development

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework