Re: My Experience with PHP5 Error Handling (and possible solutions)

From: Date: Tue, 24 Aug 2004 22:02:29 +0000
Subject: Re: My Experience with PHP5 Error Handling (and possible solutions)
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-32922@lists.php.net to get a copy of this message
Justin Patrin wrote:
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'throwInstead'); function throwInstead($err) { //I may be using thos wrong and missing things, but you get the idea throw new PEAR_Exception($err->getMessage()); }
Justin, Davey explained in the first message that he tried doing this, but it doesn't work. If you want a simple example of why this won't work for even the slightest error, take any DB_DataObject application and try using that callback :). PEAR_Error was designed for the possibility of being able to ignore an error, and the throw up there will simply jump out of a method, causing no end to troubles.
True, this breaks internal error handling for PHP4 packages, but then again, you really shouldn't be using PHP4 packages along-side PHP5 ones for too long. I know it takes a while to migrate (I have a huge code-base I haven't even started on yet), but going with something simple and elegant is much better than kludging it, then having to change our error handling yet again down the road.
How fast can you migrate DB, DB_DataObject, and HTML_QuickForm to use exceptions. Oh, and you can't break BC unless you release them as DB_v2 , DB_DataObject2, and HTML_QuickForm4, or set up another channel, or... hmmm, this might take a while. Let's set aside the "you shouldn't be doing that" and instead look at what is physically possible. It is not physically possible to migrate all of the critical php4 packages to php5-only. Who here would rather just rewrite DB_DataObject from scratch with the same API for PHP5? How about phpDocumentor? *shudder* Simple and elegant is only simple and elegant if you can actually use it effectively in a simple and elegant way. Actually, I believe simple is only useful if it is simple to debug - a clear difference from simple to code. It's very simple to code a bunch of gotos in BASIC :). Having said this, I still think using exceptions is going to be the long-term answer for php5. Making a clean break with php4 will simply hobble php5, however, as there are just no useful packages for it yet (by useful I mean packages that top the list of downloads at pear.php.net) Greg

« previous php.pear.dev (#32922) next »