File: bug38618.phpt

package info (click to toggle)
php5 5.6.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 150,376 kB
  • sloc: ansic: 727,510; php: 21,966; sh: 12,356; cpp: 8,763; xml: 6,105; yacc: 1,551; exp: 1,514; makefile: 1,461; pascal: 1,048; awk: 538; perl: 315; sql: 22
file content (105 lines) | stat: -rw-r--r-- 1,746 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
--TEST--
Bug #38618 (RecursiveArrayIterator::hasChildren() follows objects)
--FILE--
<?php # vim:ft=php

class FruitPublic
{
  public $title;

  public function __construct($title)
  {
    $this->title = $title;
  }

  public function __toString()
  {
    return $this->title;
  }
}

class FruitProtected
{
  protected $title;

  public function __construct($title)
  {
    $this->title = $title;
  }

  public function __toString()
  {
    return $this->title;
  }
}

function test_array($array, $which, $flags = 0)
{
  echo "===$which===\n";
  $it = new RecursiveArrayIterator($array, $flags);
  foreach (new RecursiveIteratorIterator($it) as $k => $fruit) {
    echo $k , ' => ', $fruit, "\n";
  }
}

$array = array(
  1 => array(
    1 => array(
      1 => 'apple',
    ),
    2 => array(
      1 => 'grape',
    ),
  ),
);

test_array($array, 'Default with array');

$array = array(
  1 => array(
    1 => array(
      1 => new FruitPublic('apple'),
    ),
    2 => array(
      1 => new FruitPublic('grape'),
    ),
  ),
);

test_array($array, 'Public Property');

$array = array(
  1 => array(
    1 => array(
      1 => new FruitProtected('apple'),
    ),
    2 => array(
      1 => new FruitProtected('grape'),
    ),
  ),
);

test_array($array, 'Protected Property');

test_array($array, 'Public Property New', RecursiveArrayIterator::CHILD_ARRAYS_ONLY);
test_array($array, 'Protected Property New', RecursiveArrayIterator::CHILD_ARRAYS_ONLY);
?>
===DONE===
<?php exit(0); ?>
?>
===DONE===
--EXPECTF--
===Default with array===
1 => apple
1 => grape
===Public Property===
title => apple
title => grape
===Protected Property===
===Public Property New===
1 => apple
1 => grape
===Protected Property New===
1 => apple
1 => grape
===DONE===