logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Code Modifications Needed for Error Handling: msg#00200

Subject: Code Modifications Needed for Error Handling
Hey PEARs,

I wanted to bring to light how we would need to go about implementing my idea for error handling, I feel that if we do this we can convince people like Sergio that BC with PHP4 can be maintained when mixing the code, but that when using PHP5 only code, it won't be stifled by tonnes of evil unncessasary BC code.

1) PEAR_Error:
Will have a default callback for all errors that will
place them on the global PEAR_ErrorStack - this can then be overriden if the user wants to do so. It should still return the PEAR_Error object, so that PEAR::isError() will still work :)

2) PEAR_ErrorStack:
Will have all PEAR_Error/Exception code removed (for returning these), it should only deal with storage/retrieval or errors, not creating them. I also think that we should decide where static and where non-static methods make sense, don't duplicate them.

3) PEAR_Exception
In the constructor, add a set_exception_handler() of a callback to a method in PEAR_Exception which will add errors to the global PEAR_ErrorStack. Again, this can be overriden ONLY by set_exception_handler, and MUST NOT be overriden by package developers in child classes.

Now, what this means is, whether you use PEAR_Error or PEAR_Exception, assuming you don't try...catch your exceptions, all errors will end up on the PEAR_ErrorStack (great if you're mixing 4&5 code). However, if you do try...catch any exception, it will not go on the ErrorStack.

Its not a huge change to PEAR_Error which I believe has callback support already built in - this means that current packages will all have their errors in PEAR_ErrorStack when using them in PHP5 - no changes by the package authors :)

What we will end up with, is several ways users should be catching errors, depending on the version of PHP its running on.

PHP4:
if (PEAR::isError()) { }
AND
if (PEAR_ErrorStack::staticHasErrors()) { }

PHP4 & PHP5:
if (PEAR_ErrorStack::staticHasErrors()) { }

PHP 5:
try { } catch () { }
OR
if (PEAR_ErrorStack::staticHasErrors()) { }

This means that PHP4 packages will work in PHP5 and developers will use PEAR_ErrorStack which will have the agreggate of exceptions and PEAR_Error's. This does NOT mean that PHP 5 packages will work in PHP 4.

If anyone is interesting in doing this work, I will make the changes to PEAR_Exception, but I don't know the PEAR_Error or PEAR_ErrorStack well enough to do this.

- Davey

p.s.

This is cross-posted to pear-core and php-dev but please keep it only on pear-core because it concerns two parts of the core PEAR package.

--
PEAR Core List Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




<Prev in Thread] Current Thread [Next in Thread>