Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.10.18

Bug #7931 hasErrors() with an error level has returned true after invoking pop().
Submitted: 2006-06-18 10:28 UTC
From: iteman2002 at yahoo dot co dot jp Assigned: cellog
Status: Closed Package: PEAR (version CVS)
PHP Version: 5.1.4 OS:
Roadmaps: (Not assigned)    
Subscription  


 [2006-06-18 10:28 UTC] iteman2002 at yahoo dot co dot jp (Atsuhiro KUBO)
Description: ------------ hasErrors() method has returned true after invoking pop() method on PEAR 1.4.9. Should pop() method remove the element from $_errorsByLevel property? Here's the patch: --- ErrorStack.php.orig 2006-06-18 19:02:58.687500000 +0900 +++ ErrorStack.php 2006-06-18 19:09:12.031250000 +0900 @@ -673,7 +673,14 @@ */ function pop() { - return @array_shift($this->_errors); + $err = @array_shift($this->_errors); + if (!is_null($err)) { + array_shift($this->_errorsByLevel[$err['level']]); + if (!count($this->_errorsByLevel[$err['level']])) { + unset($this->_errorsByLevel[$err['level']]); + } + } + return $err; } /** Test script: --------------- <?php require_once 'PEAR/ErrorStack.php'; PEAR_ErrorStack::staticPush('MyPackage', 1, 'warning'); var_dump(PEAR_ErrorStack::staticHasErrors('MyPackage', 'warning')); $stack = &PEAR_ErrorStack::singleton('MyPackage'); $stack->pop(); var_dump(PEAR_ErrorStack::staticHasErrors('MyPackage', 'warning')); ?> Expected result: ---------------- bool(true) bool(false) Actual result: -------------- bool(true) bool(true)

Comments

 [2006-06-21 09:05 UTC] kuboa at php dot net (Atsuhiro KUBO)
The patch that I posted is incorrect, since $_errorsByLevel array is reverse order to $_errors array. The correct patch as follows: --- ErrorStack.php.orig 2006-06-18 19:02:58.687500000 +0900 +++ ErrorStack.php 2006-06-21 17:39:00.605076600 +0900 @@ -673,7 +673,14 @@ */ function pop() { - return @array_shift($this->_errors); + $err = @array_shift($this->_errors); + if (!is_null($err)) { + @array_pop($this->_errorsByLevel[$err['level']]); + if (!count($this->_errorsByLevel[$err['level']])) { + unset($this->_errorsByLevel[$err['level']]); + } + } + return $err; } /**
 [2006-06-21 16:44 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2006-09-21 04:58 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!