#32993 [Com]: implemented Iterator function current() don't throw exception
| From: | tjerk dot meesters at gmail dot com | Date: | Tue, 31 May 2005 09:21:56 +0000 |
| Subject: | #32993 [Com]: implemented Iterator function current() don't throw exception | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-79751@lists.php.net to get a copy of this message | ||
ID: 32993
Comment by: tjerk dot meesters at gmail dot com
Reported By: vojtech at x dot cz
Status: Assigned
Bug Type: Zend Engine 2 problem
Operating System: *
PHP Version: 5.0.4
Assigned To: helly
New Comment:
I've had a similar problem, this time with an exception in next():
class MyIterator implements Iterator
{
function rewind() {}
function next() { throw new Exception('next()'); }
function valid() { return true; }
function current() { return 'test'; }
function key() { return 'test'; }
}
try {
foreach (new MyIterator() as $x => $y) {
// do something
}
} catch (Exception $e) {
echo "{$e->getMessage()}\n";
}
--- result ---
Fatal error: Couldn't execute method MyIterator::valid in Unknown on
line 0
--- version ---
PHP 5.0.4 (cli) on Linux (Zend Engine v2.0.4-dev)
Previous Comments:
------------------------------------------------------------------------
[2005-05-10 08:46:49] helly@php.net
Results in a SEGV in head
------------------------------------------------------------------------
[2005-05-10 06:17:40] vojtech at x dot cz
Description:
------------
It's seems there is not correctly processed exception from current()
and script ends up with fatal error.
Reproduce code:
---------------
class Test implements Iterator {
public $arr = array();
public function rewind() { return reset($this->arr); }
public function current() { throw new Exception(); }
public function key() { return key($this->arr); }
public function next() { return next($this->arr); }
public function valid() { return (current($this->arr) !==
false); }
}
$t = new Test();
$t->arr = array(1, 2, 3);
try {
foreach ($t as $v) {
; // do something
}
} catch (Exception $e) {
; // handle exception
}
Actual result:
--------------
Fatal error: Couldn't execute method Test::key in Unknown on line 0
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32993&edit=1