php-src/ext/spl/tests/spl_heap_iteration_error.phpt

54 lines
995 B
Plaintext
Raw Normal View History

2009-05-17 15:21:45 +00:00
--TEST--
SPL: Attempt to corrupt the heap while iterating
--CREDITS--
Lukasz Andrzejak meltir@meltir.com
#testfest London 2009-05-09
--FILE--
<?php
class ext_heap extends SplMaxHeap {
public $fail = false;
public function compare($val1,$val2) {
if ($this->fail)
throw new Exception('Corrupting heap',99);
return 0;
}
}
$h = new ext_heap();
$h->insert(array('foobar'));
$h->insert(array('foobar1'));
$h->insert(array('foobar2'));
try {
$h->fail=true;
foreach ($h as $value) {};
echo "I should have raised an exception here";
} catch (Exception $e) {
if ($e->getCode()!=99) echo "Unexpected exception";
}
var_dump($h);
?>
--EXPECTF--
object(ext_heap)#%d (4) {
2016-11-22 21:12:07 +00:00
["fail"]=>
2009-05-17 15:21:45 +00:00
bool(true)
2016-11-22 21:12:07 +00:00
["flags":"SplHeap":private]=>
2009-05-17 15:21:45 +00:00
int(0)
2016-11-22 21:12:07 +00:00
["isCorrupted":"SplHeap":private]=>
2009-05-17 15:21:45 +00:00
bool(true)
2016-11-22 21:12:07 +00:00
["heap":"SplHeap":private]=>
2009-05-17 15:21:45 +00:00
array(2) {
[0]=>
array(1) {
[0]=>
2016-11-22 21:12:07 +00:00
string(7) "foobar2"
2009-05-17 15:21:45 +00:00
}
[1]=>
array(1) {
[0]=>
2016-11-22 21:12:07 +00:00
string(7) "foobar1"
2009-05-17 15:21:45 +00:00
}
}
}