Re: PEAR's Error Handling and PHP5

From: Date: Wed, 07 Jun 2006 16:06:21 +0000
Subject: Re: PEAR's Error Handling and PHP5
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-42828@lists.php.net to get a copy of this message
Justin Patrin schrieb:
Some talking points: 1) Would it be possible for us to allow both PEAR_Error and Exception usage for PHP5 packages? Would this fragment our error handling too much? (This would, of course, require a version of PEAR_Error which is E_STRICT).
In places where PHP5-packages must interoperate with PHP4 ones, there won't be another solution here. No need for an E_STRICT-compatible PEAR_Error here, as in situations dealing with PHP4 packages E_STRICT will be impossible anyway. For PHP5-packages, I'm definitely pro-Exception.
2) Why are people so opposed to Exceptions form a technical standpoint? Some pros and cons as I see them: Pro Exceptions: [...]
I agree with all of these.
Con Exceptions: * Will cause multiple error handling paradigms to be used at once as likely PHP4 and PHP5 package will be used side-by-side for a time
People who want a pure PHP5 E_STRICT-compliant applications will not use PHP4 packages side-by-side with PHP5. In fact, I've heard from quite a few developers targeting PHP5 that they're trying to avoid PEAR packages these days either because they can't be sure if they'll still run when the next PHP upgrade comes or because they simply don't fit into their error handling scheme.
* They don't allow PEAR_Error's tricks such as changing error handling (dying, callback, etc), and expecting errors
Some of this stuff should not be hard to implement when all Exceptions extend a base PEAR_Exception class and possibly add a function that handles uncaught exceptions via set_exception_handler(). [...]
* They are an implicit goto (this is a very small con as this is essentially the same as returning errors from multiple calls)
And don't forget PEAR_ERROR_CALLBACK - this could be regarded an implicit goto as well. Also, as the flood of posts about a possible goto function for PHP have concluded: Goto is evil only when abused.
* Forces errors to be dealt with/rapid protytping becomes a little harder (this is IMHO a very small con, as said above, as most errors will need to be handled before code can continue anyway)
Exactly. Exceptions, just like PEAR_Errors, should be thrown only on critical errors anyway - those of a nature that don't allow the application to function as intended. These kinds of errors must always be dealt with one way or another. Throwing an exception where returning a simple boolean false would have done just fine must be strongly discouraged, or even better, forbidden in PEAR guidelines. I have yet to see someone bring up a valid reason not to use exceptions. IMHO, the advantages by far outweigh the tiny little disadvantages one might see. CU Markus

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