PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » PEAR » PEAR » Bug #7931

hasErrors() with an error level has returned true after invoking pop().

Details

Submitted2006-06-18 10:28 UTC
Fromiteman2002 at yahoo dot co dot jp
Assignedcellog
StatusClosed
PackagePEAR
PHP Version5.1.4
Roadmaps(Not assigned)

Comments

[2006-06-18 10:28 UTC] iteman2002 at yahoo dot co dot jp

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)

[2006-06-21 09:05 UTC] kuboa at php dot net

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;
}

/**