|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-04-11 17:50 UTC] sniper@php.net
[2005-04-12 10:30 UTC] helly@php.net
[2005-04-27 08:47 UTC] dmitry@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 20:00:01 2025 UTC |
Description: ------------ If you create class implementing Iterator interface and exception happens during foreach than hell breaks loose. After exception in foreach debugger shows, that processing is continued in line after the loop. In this situation exception should be thrown further. Instead it looks like exception is being kept somewhere while processing continues and is being thrown at end of the script (end of scope?). Normally (ie. operations on non-objects) this doesn`t cause crash, but if you assign object member after interrupted loop, then apache dies (1.3.28). Apart from latest shapshot the problem is present also in 5.0.3, didn`t check 5.0.4. Reproduce code: --------------- <?php class collection implements Iterator { private $_elements = array(); public function __construct() { } public function rewind() { reset($this->_elements); } public function count() { return count($this->_elements); } public function current() { $element = current($this->_elements); return $element; } public function next() { $element = next($this->_elements); return $element; } public function key() { $this->_fillCollection(); $element = key($this->_elements); return $element; } public function valid() { throw new Exception('shit happend'); return ($this->current() !== false); } } class class2 { public $dummy; } $obj = new class2(); $col = new collection(); $dummy = 'nothing'; foreach($col as $co) { //irrelevant } echo 'shouldn`t get here'; //$dummy = 'this will not crash'; $obj->dummy = 'this will crash'; ?> Expected result: ---------------- Fatal error: Uncaught exception 'Exception' with message 'shit happend' in d:\projects\opcapp\htdocs\collcrash.php:35 Stack trace: #0 d:\projects\opcapp\htdocs\collcrash.php(35): collection::valid() #1 d:\projects\opcapp\htdocs\collcrash.php(49): collection::valid() #2 d:\projects\opcapp\htdocs\collcrash.php(49): unknown() #3 {main} thrown in d:\projects\opcapp\htdocs\collcrash.php on line 35 Actual result: -------------- apache crash or (if you comment out the bottom line and remove comment from the one above it) shouldn`t get here Fatal error: Uncaught exception 'Exception' with message 'shit happend' in d:\projects\opcapp\htdocs\collcrash.php:35 Stack trace: #0 d:\projects\opcapp\htdocs\collcrash.php(35): collection::valid() #1 d:\projects\opcapp\htdocs\collcrash.php(49): collection::valid() #2 d:\projects\opcapp\htdocs\collcrash.php(49): unknown() #3 {main} thrown in d:\projects\opcapp\htdocs\collcrash.php on line 35