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:
The "do X or die()" pattern must die
July 29, 2010 @ 09:19:03

Jani Hartikainen has a suggestion for all PHP developers out there - stop using die() for handling errors!

What's the most common pattern for error handling you see in beginner's PHP code? - That's right, do_X() or die('do_X failed);. That's nice and all, as at least you have some sort of error handling, but I think this way of handling errors must go. There is no place for it in modern PHP code - it's the worst way to handle errors, not much better than not handling them at all.

He talks about why die() is so bad and some alternatives to it - trigger_error (with a custom error handler) and exceptions. When used correctly, these two can help your script correctly catch and handle errors without the mess of a die().

0 comments voice your opinion now!
die pattern triggererror exceptions error


blog comments powered by Disqus

Similar Posts

Christopher Kunz's Blog: Building PHP with cURL and libmysqlclient5

Mike\'s Blog: s/fluent/decorated

Zend Developer Zone: PHP in Action - Chapter 7, Design Patterns. Part - I

DevShed: Using Self-Saving Objects with Command Objects in PHP 5

FinalConcept.com.au: Symfony: Unbound sfForm: Unexpected extra form field named


Community Events

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


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

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