News Feed
Sections




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

Jani Hartikainen's Blog:
PHP typehinting gotcha in exceptions/methods
July 14, 2011 @ 10:41:55

Jani Hartikainen has a new post with a gotcha he came across when using typehinting in exceptions and methods.

A small gotcha I recently ran into: If you use typehinting, PHP never checks that the class your typehint specifies actually exists!

He includes simple examples that define the class type hint as some random string and PHP never throws an error for it. He also notes that it's even worse when dealing with namespaces - how it handles exceptions locally unless you specify otherwise. Of course, these "features" can be put to good use in the right situations, but they can be confusing for a developer without a keen eye.

0 comments voice your opinion now!
typehinting exception method error class missing


blog comments powered by Disqus

Similar Posts

DZone.com: PHPSpec: BDD for your classes

DevShed: Additional Methods for Using SQLite with PHP 5

Jani Hartikainen's Blog: Should a failed function return a value or throw an exception?

RubySource.com: PHP to Ruby: Modules, Mixins and Ducks

Joshua Eichorn\'s Blog: ZActiveRecord can\'t work?


Community Events

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


opinion introduction interview api performance release podcast php7 framework extension voicesoftheelephpant symfony2 series laravel library example version conference community application

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