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

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] pajoye (Pierre-Alain Joye)
move to pear, pear_errorstack is not an independent package.
 [2006-09-21 04:58 UTC] cellog (Greg Beaver)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.