From:             rashid at ds dot pg dot gda dot pl
Operating system: win 2000
PHP version:      5CVS-2005-04-11 (dev)
PHP Bug Type:     Reproducible crash
Bug description:  exception in iterator causes crash

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

-- 
Edit bug report at http://bugs.php.net/?id=32674&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=32674&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=32674&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=32674&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=32674&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=32674&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=32674&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=32674&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=32674&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=32674&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=32674&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=32674&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=32674&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=32674&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=32674&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=32674&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=32674&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=32674&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=32674&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=32674&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=32674&r=mysqlcfg

Reply via email to