Re: Patch for bugs in errorhandling in PEAR 1.3

From: Date: Wed, 03 Mar 2004 18:26:59 +0000
Subject: Re: Patch for bugs in errorhandling in PEAR 1.3
References: 1 2 3 4  Groups: php.pear.qa 
Request: Send a blank email to pear-qa+get-816@lists.php.net to get a copy of this message
Hi all, If there is no objection, I'd like to commit these methods to PEAR.php. There is one bug in the setGlobalErrorHandling() that has been fixed in PEAR::setErrorHandling(), but aside from that detail, it looks good. I won't commit until I hear a definite "that's OK" Greg Markus Kalkbrenner wrote:
Hi Greg, I agree, that my solution is a hack, but it maybe solves some problems in existing code using or based on PEAR. As I told you before (not via the list) I already implemented methods like setGlobalErrorHandling() in a class that extends PEAR (see attachment). Feel free to reuse it! Markus Please excuse that I sent this mail to so many people. But I didn't know who to add to the list, so I simply did a 'reply to all'. Am Mittwoch, 3. März 2004 14:47 schrieben Sie:
Hi all, I don't like this solution, it is by definition a hack, as it doesn't work with 4.2, and since PEAR supports 4.2, I am against it. The solution that I feel must be implemented is instead to add new static-only methods like PEAR::setGlobalErrorHandling(). If there is no significant opposition, I'll implement these in the next few weeks Greg Stefan Neufeind wrote:
Thank you Markus, I'm forwarding this again to the PEAR QA team (pear- qa@lists.php.net), since I agree with you this is quite a grave problem. We'll follow it ... thank you Stefan On 3 Mar 2004 at 11:30, Markus Kalkbrenner wrote:
Hi! Due to the fact that nobody replied to my last mail, I'll try it twice. The errorhandling of PEAR contains some bugs regarding how to detect if a method is called staticly or not. In PEAR 1.3 the check for isset($this) in methods like setErrorHandling() was replaced by isset($this) && is_a($this, 'PEAR') I already pointed out that this solution isn't safe, too. I attached a file called reproduce.php. The expected output is: first try: I'm dead! But you'll see: first try: He's still alive! second try: I'm dead! After applying the patch for PEAR.php of PEAR 1.3 I attached (patch_for_PEAR_1_3.txt) you'll get the expected output! Note: The patch only works for PHP 4.3. PHP versions before 4.3 aren't affected and the behaviour is the same as before. I hope to get some feedback this time. Regards Markus
------------------------------------------------------------------------ <?php require_once("PEAR.php"); class PEARExtension extends PEAR {
    /**
    * Workaround for bug in PEAR
    * See http://bugs.php.net/bug.php?id=25714
    */
    function setGlobalErrorHandling($mode = null, $options = null)
    {
        $setmode     = &$GLOBALS['_PEAR_default_error_mode'];
        $setoptions  = &$GLOBALS['_PEAR_default_error_options'];
        switch ($mode) {
            case PEAR_ERROR_RETURN:
            case PEAR_ERROR_PRINT:
            case PEAR_ERROR_TRIGGER:
            case PEAR_ERROR_DIE:
            case PEAR_ERROR_EXCEPTION:
            case null:
                $setmode = $mode;
                $setoptions = $options;
                break;
            case PEAR_ERROR_CALLBACK:
                $setmode = $mode;
                if ((is_string($options) && function_exists($options)) ||
                    (is_array($options) && method_exists(@$options[0], @$options[1])))
                {
                    $setoptions = $options;
                } else {
                    trigger_error("invalid error callback", E_USER_WARNING);
                }
                break;
            default:
                trigger_error("invalid error mode", E_USER_WARNING);
                break;
        }
    }
    /**
    * Workaround for bug in PEAR
    * See http://bugs.php.net/bug.php?id=25714
    */
    function pushGlobalErrorHandling($mode, $options = null)
    {
        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
        $def_mode    = &$GLOBALS['_PEAR_default_error_mode'];
        $def_options = &$GLOBALS['_PEAR_default_error_options'];
        $stack[] = array($def_mode, $def_options);
        PEARExtension::setGlobalErrorHandling($mode, $options);
        $stack[] = array($mode, $options);
        return true;
    }
    /**
    * Workaround for bug in PEAR
    * See http://bugs.php.net/bug.php?id=25714
    */
    function popGlobalErrorHandling()
    {
        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
        array_pop($stack);
        list($mode, $options) = $stack[sizeof($stack) - 1];
        array_pop($stack);
        PEARExtension::setGlobalErrorHandling($mode, $options);
        return true;
    }
} ?>


« previous php.pear.qa (#816) next »