News Feed
Sections




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

Evert Pot's Blog:
Numeric string comparison in PHP
April 26, 2011 @ 09:23:47

In this new post to his blog Evert Pot reminds you (the PHP developer) about the loose and strict typing checks that you need to do when checking the values of your variables and never just assume. PHP's loose typing tendencies can cause issues if you're not paying attention.

As long as you make sure you always use strict checking (=== and !==) where you can, and fall back to the loose checks when you must. As a PHP developer, I think it's very important to understand and memorize exactly how these work, whether you're writing new code, or maintaining existing code.

He points out a specific example of some code that seems counter-intuitive when you compare how it reads and how it actually works (strings converted to floats and evaluated)

The moral is: always do strict checks when you are able to.
0 comments voice your opinion now!
numeric comparison evaluate loose typing typecheck


blog comments powered by Disqus

Similar Posts

PHPSlices.com: PHP 5.3 vs ASP.NET 4.0 neutral comparison

DevShed: The Switch Statement and Arrays

Dhani's Blog: Creating Guest Book with PHP

Tobias Schlitt's Blog: Funny speed considerations

Matt Butcher's Blog: A Set of Objects in PHP: Arrays vs. SplObjectStorage


Community Events





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


series framework threedevsandamaybe project wordpress code release developer podcast configure api community interview library application language introduction laravel list bugfix

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