xref: /PHP-5.6/ext/spl/tests/array_013.phpt (revision 610c7fbe)
1--TEST--
2SPL: ArrayIterator::append
3--FILE--
4<?php
5
6if (!class_exists('NoRewindIterator', false))
7{
8	require_once(dirname(__FILE__) . '/../examples/norewinditerator.inc');
9}
10
11echo "===Array===\n";
12
13$a = array(0 => 'zero', 1 => 'one', 2 => 'two');
14$it = new ArrayIterator($a);
15
16foreach($it as $key => $val)
17{
18	echo "$key=>$val\n";
19}
20
21echo "===Append===\n";
22
23$it->append('three');
24$it->append('four');
25
26foreach(new NoRewindIterator($it) as $key => $val)
27{
28	echo "$key=>$val\n";
29}
30
31echo "===Object===\n";
32
33class 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
45foreach($it as $key => $val)
46{
47	echo "$key=>$val\n";
48}
49
50echo "===Append===\n";
51
52$it->append('three');
53$it->append('four');
54
55foreach(new NoRewindIterator($it) as $key => $val)
56{
57	echo "$key=>$val\n";
58}
59
60var_dump($o->{0}); /* doesn't wotk anyway */
61
62?>
63===DONE===
64<?php exit(0); ?>
65--EXPECTF--
66===Array===
670=>zero
681=>one
692=>two
70===Append===
713=>three
724=>four
73===Object===
74zero=>0
75one=>1
76two=>2
77===Append===
78
79Catchable fatal error: ArrayIterator::append(): Cannot append properties to objects, use ArrayIterator::offsetSet() instead in %sarray_013.php on line %d
80