PEAR_Warning is in CVS for pre-devel review

From: Date: Sat, 04 Sep 2004 03:59:08 +0000
Subject: PEAR_Warning is in CVS for pre-devel review
Groups: php.pear.dev php.pear.core 
Request: Send a blank email to pear-dev+get-33213@lists.php.net to get a copy of this message
NOTE: all followups to pear-core@lists.php.net please. Hi all, I have written up some basic code for PEAR_Warning, which can be found in PEAR/Warning.php. This is not even devel code, consider it pre-RFC code to explain what I'm thinking without any sugar :). Basic design principles: 1) lazy loading: as a package developer, you do not need to require_once 'PEAR/Warning.php'; in order to use PEAR_Warning! <?php if (class_exists('PEAR_Warning')) {
    PEAR_Warning::add(...);
} ?> This has the added bonus that on production sites, performance will be better (although logging of warnings will not occur). 2) transaction-style warning handling Similar to try/catch or database transactions. <?php PEAR_Warning::begin(); // do stuff if (PEAR_Warning::hasWarnings()) {
    $warnings = PEAR_Warning::end();
    // do stuff with warnings
} ?> Incidentally, I toyed with the idea of PEAR_Warning::commit() but that doesn't really describe what's happening. 3) Local warning handling is still possible Instantiating a PEAR_Warning and using localAdd() instead of add() will allow custom error stacks for tasks like the warnings that one might need to raise in a parser, or other complex task. 4) Total compatibility with PEAR_Exception You can pass in an exception object as the warning. The array returned from PEAR_Warning::end() can be used as a cause for a new PEAR_Exception-based object (voila, multiple errors can now be handled). 5) Total compatibility with PEAR_ErrorStack If PEAR_ErrorStack exists, a hidden callback in PEAR_ErrorStack will pass all warnings directly to PEAR_Warning, intermingling with the existing PEAR_Warning stack. Read: can replace PEAR_ErrorStack, but the API is different, as is the design philosophy. 6) warning severity is still possible, and with PEAR_Warning::setErrorHandling(), you can select the kind of warnings that will be handled. 7) under 400 lines with comments. Let me stress: THIS IS EXPERIMENTAL IDEA CODE. IT ISN'T EVEN FULLY TESTED. OK. Now, if you have any code-based criticisms, including "this sucks, why can't you do it this way?" I need to hear them. I'm going away for the weekend, but will be back in time to respond to comments. If you can provide alternative ideas in your criticisms, this would be very helpful, especially for general criticisms of the design choices. Thanks, Greg

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