~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to ext/spl/tests/array_013.phpt

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

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