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===
|