php-src/ext/spl/tests/array_019.phpt
Nikita Popov ede663f381 Convert iterator by reference errors to exceptions
I'm using RuntimeException in SPL, because other SPL classes that
throw this error used it. Error is used for everything else, because
that's what core does.
2018-02-19 21:58:56 +01:00

34 lines
780 B
PHP

--TEST--
SPL: ArrayIterator and foreach by reference
--FILE--
<?php
$ar = new ArrayObject(array(1)); foreach($ar as &$v) var_dump($v);
$ar = new ArrayIterator(array(2)); foreach($ar as &$v) var_dump($v);
$ar = new RecursiveArrayIterator(array(3)); foreach($ar as &$v) var_dump($v);
class ArrayIteratorEx extends ArrayIterator
{
function current()
{
return ArrayIterator::current();
}
}
$ar = new ArrayIteratorEx(array(4)); foreach($ar as $v) var_dump($v);
$ar = new ArrayIteratorEx(array(5)); foreach($ar as &$v) var_dump($v);
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
int(1)
int(2)
int(3)
int(4)
Fatal error: Uncaught RuntimeException: An iterator cannot be used with foreach by reference in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d