1--TEST--
2SPL: Attempt to corrupt the heap while iterating
3--CREDITS--
4Lukasz Andrzejak meltir@meltir.com
5#testfest London 2009-05-09
6--FILE--
7<?php
8class ext_heap extends SplMaxHeap {
9  public $fail = false;
10  public function compare($val1,$val2) {
11    if ($this->fail)
12      throw new Exception('Corrupting heap',99);
13    return 0;
14  }
15}
16
17$h = new ext_heap();
18$h->insert(array('foobar'));
19$h->insert(array('foobar1'));
20$h->insert(array('foobar2'));
21
22try {
23  $h->fail=true;
24  foreach ($h as $value) {};
25  echo "I should have raised an exception here";
26} catch (Exception $e) {
27  if ($e->getCode()!=99) echo "Unexpected exception";
28}
29
30var_dump($h);
31?>
32--EXPECTF--
33object(ext_heap)#%d (4) {
34  [%u|b%"fail"]=>
35  bool(true)
36  [%u|b%"flags":%u|b%"SplHeap":private]=>
37  int(0)
38  [%u|b%"isCorrupted":%u|b%"SplHeap":private]=>
39  bool(true)
40  [%u|b%"heap":%u|b%"SplHeap":private]=>
41  array(2) {
42    [0]=>
43    array(1) {
44      [0]=>
45      %unicode|string%(7) "foobar2"
46    }
47    [1]=>
48    array(1) {
49      [0]=>
50      %unicode|string%(7) "foobar1"
51    }
52  }
53}
54