Re: Call for Review: RFC for Error Handling in PHP5 packages
| From: | Sergio Carvalho | Date: | Sat, 07 Aug 2004 18:45:04 +0000 |
| Subject: | Re: Call for Review: RFC for Error Handling in PHP5 packages | ||
| References: | 1 2 3 4 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-32507@lists.php.net to get a copy of this message | ||
Davey wrote:
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
Lukas Smith wrote:So, you are proposing we drop down to the common denominator between Exceptions and Return Codes, effectively disallowing: - Deferral of error checking: http://wiki.ciaweb.net/yawiki/index.php?area=PEAR_Dev&page=RfcExceptionUse#toc15 - Deferral of recovery: http://wiki.ciaweb.net/yawiki/index.php?area=PEAR_Dev&page=RfcExceptionUse all to avoid the impossibility of using Exceptions in PHP4 code. Personally, I think this is a place where we should cut away from the ties with PHP4 error handling. PEAR_ErrorStack does a very good job given the constraints in PHP4, but would be a drag on PHP5-only packages -- which should run in E_STRICT anyway, precluding most legacy package use anyway. Cheers, SérgioDavey wrote:<?php require_once 'PEAR.php'; require_once 'XML/Tree.php'; // a PHP 4 class that works fine in PHP 5, uses PEAR_Error $tree = new XML_Tree; $root = $tree->addRoot($_GET['root_name']); // PEAR_Error Handling if (PEAR::isError($root)) {Davey wrote:I would urge that you consider this point - we MUST unify how errors are recieved by the USER, otherwise we're going to have tangles of error handling on the users end.On an additional note, it would be possible for the user to specify a callback for PEAR_ErrorStack which would re-throw the exceptions, this could be the way to placate everybody - those who use exceptions only can have PEAR_ErrorStack re-throw them and ignore the stack whilst those who don't use the stack. Greg - is it possible to have this as like... a special callback? like: PEAR_ErrorStack::throwExceptions(); would add an additional callback for all errors to go through (so even if you repackage the error and stuff, it will then throw the exception with the repackaged error)Uhm I still dont quite see how your proposal works. Could you try to explain with a bit of pseudo code? Also could you try to note the possibl edisadvantages of such a system. regards, Lukasecho $root->message;} // a PHP 5 class that uses PEAR_Exception require_once 'Some/Fake/Package.php'; // PEAR_Exception handling try {$fake = new Fake_Package;} catch (Fake_Package_Exception $e) {echo $e;} /* Why make the user jump through two hoops to check the errors on different classes? Wouldn't this be better: */ // a PHP4 class that works fine in PHP 5, uses PEAR_Error internally // but places errors on the stack - the user is never returned a PEAR_Error require_once 'XML/Tree2.php'; // a PHP 5 class the uses exceptions internally, also places errors // on the stack - exceptions never bubble out of the package require_once 'Some/Fake/Package2.php'; $tree = new XML_Tree2; $root = $tree->addRoot($_GET['root_name']); $fake = new Some_Fake_Package2; // The user only does ONE type of error checking // even though the packages used PEAR_Error and Exceptions if (PEAR_ErrorStack::staticHasErrors()) {$errors = PEAR_ErrorStack::getErrors(); foreach ($errors as $error) { echo $error->message; }} ?> The only real disadvantage of this, is that if you just use PHP 4 or just PHP 5 classes they still have to load PEAR_ErrorStack. - Davey
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc