ID:               32674
 Updated by:       [EMAIL PROTECTED]
 Reported By:      rashid at ds dot pg dot gda dot pl
 Status:           Verified
 Bug Type:         Zend Engine 2 problem
 Operating System: *
 PHP Version:      5CVS-2005-04-11
 New Comment:

The illegal opcde error can be produced easily. Actually no iterator
method that throws an exception doesn't result in direct script
termination in case of try/catch block absence. This said a much easier
test case is the following:
--TEST--
Bug #32674 (exception in iterator causes crash).
--FILE--
<?php
class MyCollection implements Iterator
{
        public function rewind() { }
        
        public function current() { }
        
        public function next() { }
        
        public function key() { }
        
        public function valid()
        {
                throw new Exception('shit happend');
        }
}
        
$obj = new stdClass();
$col = new MyCollection();
        
foreach($col as $co)
{
        //irrelevant
}

echo 'shouldn`t get here';
$obj->dummy = 'this will crash';
exit(0);
?>
===DONE===
--EXPECTF--

Unfortunatley even handling exceptions for all method calls in FE_RESET
and FE_FETCH opcode doesn't help since then SWITCH_FREE still ignores
the exception.

In the end it seems that this is an error where either the executor
loop needs to check for the exceptions or the lw level function handler
needs to do a direct long jump on exceptions (the latter is bad because
it doesn't free anything and ha problems with catch blocks).


Previous Comments:
------------------------------------------------------------------------

[2005-04-11 17:50:34] [EMAIL PROTECTED]

I get this:

Fatal error: Invalid opcode 137/1/8. in /home/jani/t.php on line 50


------------------------------------------------------------------------

[2005-04-11 17:26:08] rashid at ds dot pg dot gda dot pl

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 this bug report at http://bugs.php.net/?id=32674&edit=1

Reply via email to