ReflectionClass_isIterateable_001.phpt 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. --TEST--
  2. ReflectionClass::isIterateable()
  3. --CREDITS--
  4. Robin Fernandes <robinf@php.net>
  5. Steve Seear <stevseea@php.net>
  6. --FILE--
  7. <?php
  8. Interface ExtendsIterator extends Iterator {
  9. }
  10. Interface ExtendsIteratorAggregate extends IteratorAggregate {
  11. }
  12. Class IteratorImpl implements Iterator {
  13. public function next() {}
  14. public function key() {}
  15. public function rewind() {}
  16. public function current() {}
  17. public function valid() {}
  18. }
  19. Class IterarorAggregateImpl implements IteratorAggregate {
  20. public function getIterator() {}
  21. }
  22. Class ExtendsIteratorImpl extends IteratorImpl {
  23. }
  24. Class ExtendsIteratorAggregateImpl extends IterarorAggregateImpl {
  25. }
  26. Class A {
  27. }
  28. $classes = array('Traversable', 'Iterator', 'IteratorAggregate', 'ExtendsIterator', 'ExtendsIteratorAggregate',
  29. 'IteratorImpl', 'IterarorAggregateImpl', 'ExtendsIteratorImpl', 'ExtendsIteratorAggregateImpl', 'A');
  30. foreach($classes as $class) {
  31. $rc = new ReflectionClass($class);
  32. echo "Is $class iterable? ";
  33. var_dump($rc->isIterateable());
  34. }
  35. echo "\nTest invalid params:\n";
  36. $rc = new ReflectionClass('IteratorImpl');
  37. var_dump($rc->isIterateable(null));
  38. var_dump($rc->isIterateable(null, null));
  39. var_dump($rc->isIterateable(1));
  40. var_dump($rc->isIterateable(1.5));
  41. var_dump($rc->isIterateable(true));
  42. var_dump($rc->isIterateable('X'));
  43. var_dump($rc->isIterateable(null));
  44. echo "\nTest static invocation:\n";
  45. ReflectionClass::isIterateable();
  46. ?>
  47. --EXPECTF--
  48. Is Traversable iterable? bool(false)
  49. Is Iterator iterable? bool(false)
  50. Is IteratorAggregate iterable? bool(false)
  51. Is ExtendsIterator iterable? bool(false)
  52. Is ExtendsIteratorAggregate iterable? bool(false)
  53. Is IteratorImpl iterable? bool(true)
  54. Is IterarorAggregateImpl iterable? bool(true)
  55. Is ExtendsIteratorImpl iterable? bool(true)
  56. Is ExtendsIteratorAggregateImpl iterable? bool(true)
  57. Is A iterable? bool(false)
  58. Test invalid params:
  59. Warning: ReflectionClass::isIterateable() expects exactly 0 parameters, 1 given in %s on line 34
  60. NULL
  61. Warning: ReflectionClass::isIterateable() expects exactly 0 parameters, 2 given in %s on line 35
  62. NULL
  63. Warning: ReflectionClass::isIterateable() expects exactly 0 parameters, 1 given in %s on line 36
  64. NULL
  65. Warning: ReflectionClass::isIterateable() expects exactly 0 parameters, 1 given in %s on line 37
  66. NULL
  67. Warning: ReflectionClass::isIterateable() expects exactly 0 parameters, 1 given in %s on line 38
  68. NULL
  69. Warning: ReflectionClass::isIterateable() expects exactly 0 parameters, 1 given in %s on line 39
  70. NULL
  71. Warning: ReflectionClass::isIterateable() expects exactly 0 parameters, 1 given in %s on line 40
  72. NULL
  73. Test static invocation:
  74. Fatal error: Non-static method ReflectionClass::isIterateable() cannot be called statically in %s on line 43