News Feed
Sections




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

Brandon Savage's Blog:
Avoiding Notices When to Use isset() and empty()
September 23, 2009 @ 08:47:13

If you've ever been bothered by those pesky NOTICEs when running your code, you know that you can wrap evaluations or check things with an empty or isset call to make them go away. Brandon Savage has a new post that can help you decide which one to use when, though.

As developers, we want to develop code that never emits notices or warnings, and PHP gets a bit antsy when we develop code that utilizes uninitialized variables. Lucky for us, PHP makes it easy to test for these variables without getting these notices. [...] PHP (like most languages) evaluates a logical argument left to right. For an AND condition, both conditions have to be true; PHP stops evaluating if it finds any condition untrue.

He suggests that the case to use isset() is more when you just want to use another check in the conditional but don't want to be bothered if the variable isn't there. A call to empty(), however, also evaluates the contents of the variable if it exists. Be careful, though - empty() returns false if the value of the variable is false - so take care in your use and always test scripts with multiple values.

0 comments voice your opinion now!
avoid notice tutorial isset empty


blog comments powered by Disqus

Similar Posts

Nefarious Designs: Object-Oriented PHP Part 2: Relationships

HowToForge.com: LAMP Installation On Ubuntu 6.06 For Linux Noobs

VG Tech: Swagger Docs in ZF2 with Examples - Part 2: Swagger UI

Zend Developer Zone: Profiling PHP Applications With xdebug

NetTuts.com: Aspect-Oriented Programming in PHP


Community Events

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


community interview example framework voicesoftheelephpant laravel php7 api video introduction library language laravel5 series development opinion unittest version podcast release

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