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

Justin Carmony's Blog: PHP, Sessions, __sleep, and Exceptions

DevShed: Positioning Strings with the show_xy() Method in PDF Documents with PHP 5

Derick Rethans' Blog: Overloaded properties (__get)

Jani Hartikainen's Blog: Common programming errors and how to avoid them

Web Development Blog: Tutorial: Create a zip file from folders on the fly


Community Events





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


version composer introduction update release opinion podcast tool voicesoftheelephpant package framework install laravel series security symfony interview community language library

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