News Feed
Sections




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

Ben Ramsey's Blog:
Undefined Constant Is a String?
December 21, 2006 @ 07:34:00

Constants can be handy when used correctly. Unfortunately, there's some small issues you might want to watch out for. Ben Ramsey discovered one while working with another's code - an undefined constant acting like a string.

From the I-noticed-this-one-day-while-looking-at-a-co-worker's-code department comes a tale about the use of undefined constants in PHP'"and relying on this twisted "feature" to make an application function properly.

He relays a little story about the errant code and noticed the constant that wasn't defined and how PHP was treating it like a string. After searching the manual, though, he finds a reference related to the situation showing that it will only throw an E_NOTICE when this happens.

Ben's suggestion is for a bit more than that - at the very least an E_WARNING. Having it down at E_NOTICE won't be seen by most with the default php.ini, and he gives an example as to why it's a bad thing (passing this string/constant into a function and how it handles it).

0 comments voice your opinion now!
undefined constant string value enotice ewarning phpiin undefined constant string value enotice ewarning phpiin


blog comments powered by Disqus

Similar Posts

DZone.com: Practical PHP Refactoring: Encapsulate Downcast (and Wrapping)

Brian Moon's Blog: Short Array Syntax for PHP

NETTUTS.com: Sanitize and Validate Data with PHP Filters

NetTuts.com: Refactoring Legacy Code: Part 2 - Magic Strings & Constants

Mike Purcell's Blog: PHPUnit - Upgrade - Convert assertType to assertInternalType


Community Events





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


update library interview release framework zendserver deployment introduction community series language podcast symfony api opinion tips laravel package install unittest

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