bug38618.phpt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. --TEST--
  2. Bug #38618 (RecursiveArrayIterator::hasChildren() follows objects)
  3. --FILE--
  4. <?php
  5. class FruitPublic
  6. {
  7. public $title;
  8. public function __construct($title)
  9. {
  10. $this->title = $title;
  11. }
  12. public function __toString()
  13. {
  14. return $this->title;
  15. }
  16. }
  17. class FruitProtected
  18. {
  19. protected $title;
  20. public function __construct($title)
  21. {
  22. $this->title = $title;
  23. }
  24. public function __toString()
  25. {
  26. return $this->title;
  27. }
  28. }
  29. function test_array($array, $which, $flags = 0)
  30. {
  31. echo "===$which===\n";
  32. $it = new RecursiveArrayIterator($array, $flags);
  33. foreach (new RecursiveIteratorIterator($it) as $k => $fruit) {
  34. echo $k , ' => ', $fruit, "\n";
  35. }
  36. }
  37. $array = array(
  38. 1 => array(
  39. 1 => array(
  40. 1 => 'apple',
  41. ),
  42. 2 => array(
  43. 1 => 'grape',
  44. ),
  45. ),
  46. );
  47. test_array($array, 'Default with array');
  48. $array = array(
  49. 1 => array(
  50. 1 => array(
  51. 1 => new FruitPublic('apple'),
  52. ),
  53. 2 => array(
  54. 1 => new FruitPublic('grape'),
  55. ),
  56. ),
  57. );
  58. test_array($array, 'Public Property');
  59. $array = array(
  60. 1 => array(
  61. 1 => array(
  62. 1 => new FruitProtected('apple'),
  63. ),
  64. 2 => array(
  65. 1 => new FruitProtected('grape'),
  66. ),
  67. ),
  68. );
  69. test_array($array, 'Protected Property');
  70. test_array($array, 'Public Property New', RecursiveArrayIterator::CHILD_ARRAYS_ONLY);
  71. test_array($array, 'Protected Property New', RecursiveArrayIterator::CHILD_ARRAYS_ONLY);
  72. ?>
  73. --EXPECT--
  74. ===Default with array===
  75. 1 => apple
  76. 1 => grape
  77. ===Public Property===
  78. title => apple
  79. title => grape
  80. ===Protected Property===
  81. ===Public Property New===
  82. 1 => apple
  83. 1 => grape
  84. ===Protected Property New===
  85. 1 => apple
  86. 1 => grape