xref: /PHP-5.5/ext/spl/tests/bug38618.phpt (revision 06cef683)
1--TEST--
2Bug #38618 (RecursiveArrayIterator::hasChildren() follows objects)
3--FILE--
4<?php # vim:ft=php
5
6class FruitPublic
7{
8  public $title;
9
10  public function __construct($title)
11  {
12    $this->title = $title;
13  }
14
15  public function __toString()
16  {
17    return $this->title;
18  }
19}
20
21class FruitProtected
22{
23  protected $title;
24
25  public function __construct($title)
26  {
27    $this->title = $title;
28  }
29
30  public function __toString()
31  {
32    return $this->title;
33  }
34}
35
36function test_array($array, $which, $flags = 0)
37{
38  echo "===$which===\n";
39  $it = new RecursiveArrayIterator($array, $flags);
40  foreach (new RecursiveIteratorIterator($it) as $k => $fruit) {
41    echo $k , ' => ', $fruit, "\n";
42  }
43}
44
45$array = array(
46  1 => array(
47    1 => array(
48      1 => 'apple',
49    ),
50    2 => array(
51      1 => 'grape',
52    ),
53  ),
54);
55
56test_array($array, 'Default with array');
57
58$array = array(
59  1 => array(
60    1 => array(
61      1 => new FruitPublic('apple'),
62    ),
63    2 => array(
64      1 => new FruitPublic('grape'),
65    ),
66  ),
67);
68
69test_array($array, 'Public Property');
70
71$array = array(
72  1 => array(
73    1 => array(
74      1 => new FruitProtected('apple'),
75    ),
76    2 => array(
77      1 => new FruitProtected('grape'),
78    ),
79  ),
80);
81
82test_array($array, 'Protected Property');
83
84test_array($array, 'Public Property New', RecursiveArrayIterator::CHILD_ARRAYS_ONLY);
85test_array($array, 'Protected Property New', RecursiveArrayIterator::CHILD_ARRAYS_ONLY);
86?>
87===DONE===
88<?php exit(0); ?>
89?>
90===DONE===
91--EXPECTF--
92===Default with array===
931 => apple
941 => grape
95===Public Property===
96title => apple
97title => grape
98===Protected Property===
99===Public Property New===
1001 => apple
1011 => grape
102===Protected Property New===
1031 => apple
1041 => grape
105===DONE===
106