Annotation of embedaddon/php/ext/spl/tests/array_013.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: SPL: ArrayIterator::append
! 3: --FILE--
! 4: <?php
! 5:
! 6: if (!class_exists('NoRewindIterator', false))
! 7: {
! 8: require_once(dirname(__FILE__) . '/../examples/norewinditerator.inc');
! 9: }
! 10:
! 11: echo "===Array===\n";
! 12:
! 13: $a = array(0 => 'zero', 1 => 'one', 2 => 'two');
! 14: $it = new ArrayIterator($a);
! 15:
! 16: foreach($it as $key => $val)
! 17: {
! 18: echo "$key=>$val\n";
! 19: }
! 20:
! 21: echo "===Append===\n";
! 22:
! 23: $it->append('three');
! 24: $it->append('four');
! 25:
! 26: foreach(new NoRewindIterator($it) as $key => $val)
! 27: {
! 28: echo "$key=>$val\n";
! 29: }
! 30:
! 31: echo "===Object===\n";
! 32:
! 33: class test
! 34: {
! 35: public $zero = 0;
! 36: protected $pro;
! 37: public $one = 1;
! 38: private $pri;
! 39: public $two = 2;
! 40: }
! 41:
! 42: $o = new test;
! 43: $it = new ArrayIterator($o);
! 44:
! 45: foreach($it as $key => $val)
! 46: {
! 47: echo "$key=>$val\n";
! 48: }
! 49:
! 50: echo "===Append===\n";
! 51:
! 52: $it->append('three');
! 53: $it->append('four');
! 54:
! 55: foreach(new NoRewindIterator($it) as $key => $val)
! 56: {
! 57: echo "$key=>$val\n";
! 58: }
! 59:
! 60: var_dump($o->{0}); /* doesn't wotk anyway */
! 61:
! 62: ?>
! 63: ===DONE===
! 64: <?php exit(0); ?>
! 65: --EXPECTF--
! 66: ===Array===
! 67: 0=>zero
! 68: 1=>one
! 69: 2=>two
! 70: ===Append===
! 71: 3=>three
! 72: 4=>four
! 73: ===Object===
! 74: zero=>0
! 75: one=>1
! 76: two=>2
! 77: ===Append===
! 78:
! 79: Catchable fatal error: ArrayIterator::append(): Cannot append properties to objects, use ArrayIterator::offsetSet() instead in %sarray_013.php on line %d
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>