ReflectionClass_isIterateable_001.phpt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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(): void {}
  14. public function key(): mixed {}
  15. public function rewind(): void {}
  16. public function current(): mixed {}
  17. public function valid(): bool {}
  18. }
  19. Class IteratorAggregateImpl implements IteratorAggregate {
  20. public function getIterator(): Traversable {}
  21. }
  22. Class ExtendsIteratorImpl extends IteratorImpl {
  23. }
  24. Class ExtendsIteratorAggregateImpl extends IteratorAggregateImpl {
  25. }
  26. Class A {
  27. }
  28. $classes = array('Traversable', 'Iterator', 'IteratorAggregate', 'ExtendsIterator', 'ExtendsIteratorAggregate',
  29. 'IteratorImpl', 'IteratorAggregateImpl', '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 static invocation:\n";
  36. ReflectionClass::isIterateable();
  37. ?>
  38. --EXPECTF--
  39. Is Traversable iterable? bool(false)
  40. Is Iterator iterable? bool(false)
  41. Is IteratorAggregate iterable? bool(false)
  42. Is ExtendsIterator iterable? bool(false)
  43. Is ExtendsIteratorAggregate iterable? bool(false)
  44. Is IteratorImpl iterable? bool(true)
  45. Is IteratorAggregateImpl iterable? bool(true)
  46. Is ExtendsIteratorImpl iterable? bool(true)
  47. Is ExtendsIteratorAggregateImpl iterable? bool(true)
  48. Is A iterable? bool(false)
  49. Test static invocation:
  50. Fatal error: Uncaught Error: Non-static method ReflectionClass::isIterateable() cannot be called statically in %s:%d
  51. Stack trace:
  52. #0 {main}
  53. thrown in %s on line %d