[PATCH] bug in pear/Log/Log/composite.php
| From: | Roman Neuhauser | Date: | Tue, 25 Mar 2003 15:30:28 +0000 |
| Subject: | [PATCH] bug in pear/Log/Log/composite.php | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-14605@lists.php.net to get a copy of this message | ||
There is a bug in the Log_composite class: although it stores
references, it acts on their copies: all messages sent to the children
enumerate the list with foreach().
This patch also contains a small optimization for the $_children
enumerations that seems to speed it up by about 5%.
--
If you cc me or remove the list(s) completely I'll most likely ignore
your message. see http://www.eyrie.org./~eagle/faqs/questions.html
Index: composite.php =================================================================== RCS file: /repository/pear/Log/Log/composite.php,v retrieving revision 1.8 diff -u -r1.8 composite.php --- composite.php 2 Dec 2002 05:23:00 -0000 1.8 +++ composite.php 25 Mar 2003 16:07:03 -0000 @@ -20,6 +20,7 @@ * @var array */ var $_children = array(); + var $_ids = array(); /** @@ -44,9 +45,8 @@ function open() { if (!$this->_opened) { - reset($this->_children); - foreach ($this->_children as $child) { - $child->open(); + foreach ($this->_ids as $cid) { + $this->_children[$cid]->open(); } } } @@ -59,9 +59,8 @@ function close() { if ($this->_opened) { - reset($this->_children); - foreach ($this->_children as $child) { - $child->close(); + foreach ($this->_ids as $cid) { + $this->_children[$cid]->close(); } } } @@ -79,9 +78,8 @@ */ function log($message, $priority = PEAR_LOG_INFO) { - reset($this->_children); - foreach ($this->_children as $child) { - $child->log($message, $priority); + foreach ($this->_ids as $cid) { + $this->_children[$cid]->log($message, $priority); } $this->notifyAll(array('priority' => $priority, 'message' => $message)); @@ -115,7 +113,7 @@ } $child->_childID = uniqid(rand()); - + $this->_ids[$child->_childID] = $child->_childID;; $this->_children[$child->_childID] = &$child; } @@ -129,6 +127,7 @@ function removeChild($child) { if (isset($this->_children[$child->_childID])) { + unset($this->_ids[$child->_childID]); unset($this->_children[$child->_childID]); } }
Index: composite.php =================================================================== RCS file: /repository/pear/Log/Log/composite.php,v retrieving revision 1.8 diff -u -r1.8 composite.php --- composite.php 2 Dec 2002 05:23:00 -0000 1.8 +++ composite.php 25 Mar 2003 16:07:03 -0000 @@ -20,6 +20,7 @@ * @var array */ var $_children = array(); + var $_ids = array(); /** @@ -44,9 +45,8 @@ function open() { if (!$this->_opened) { - reset($this->_children); - foreach ($this->_children as $child) { - $child->open(); + foreach ($this->_ids as $cid) { + $this->_children[$cid]->open(); } } } @@ -59,9 +59,8 @@ function close() { if ($this->_opened) { - reset($this->_children); - foreach ($this->_children as $child) { - $child->close(); + foreach ($this->_ids as $cid) { + $this->_children[$cid]->close(); } } } @@ -79,9 +78,8 @@ */ function log($message, $priority = PEAR_LOG_INFO) { - reset($this->_children); - foreach ($this->_children as $child) { - $child->log($message, $priority); + foreach ($this->_ids as $cid) { + $this->_children[$cid]->log($message, $priority); } $this->notifyAll(array('priority' => $priority, 'message' => $message)); @@ -115,7 +113,7 @@ } $child->_childID = uniqid(rand()); - + $this->_ids[$child->_childID] = $child->_childID;; $this->_children[$child->_childID] = &$child; } @@ -129,6 +127,7 @@ function removeChild($child) { if (isset($this->_children[$child->_childID])) { + unset($this->_ids[$child->_childID]); unset($this->_children[$child->_childID]); } }