1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 16:22:37 +01:00
Files
archived-php-src/ext/reflection/tests/ReflectionClass_isIterateable_001.phpt
Máté Kocsis 75a678a7e3 Declare tentative return types for Zend (#7251)
Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2021-07-19 13:44:20 +02:00

60 lines
1.7 KiB
PHP

--TEST--
ReflectionClass::isIterateable()
--CREDITS--
Robin Fernandes <robinf@php.net>
Steve Seear <stevseea@php.net>
--FILE--
<?php
Interface ExtendsIterator extends Iterator {
}
Interface ExtendsIteratorAggregate extends IteratorAggregate {
}
Class IteratorImpl implements Iterator {
public function next(): void {}
public function key(): mixed {}
public function rewind(): void {}
public function current(): mixed {}
public function valid(): bool {}
}
Class IteratorAggregateImpl implements IteratorAggregate {
public function getIterator(): Traversable {}
}
Class ExtendsIteratorImpl extends IteratorImpl {
}
Class ExtendsIteratorAggregateImpl extends IteratorAggregateImpl {
}
Class A {
}
$classes = array('Traversable', 'Iterator', 'IteratorAggregate', 'ExtendsIterator', 'ExtendsIteratorAggregate',
'IteratorImpl', 'IteratorAggregateImpl', 'ExtendsIteratorImpl', 'ExtendsIteratorAggregateImpl', 'A');
foreach($classes as $class) {
$rc = new ReflectionClass($class);
echo "Is $class iterable? ";
var_dump($rc->isIterateable());
}
echo "\nTest static invocation:\n";
ReflectionClass::isIterateable();
?>
--EXPECTF--
Is Traversable iterable? bool(false)
Is Iterator iterable? bool(false)
Is IteratorAggregate iterable? bool(false)
Is ExtendsIterator iterable? bool(false)
Is ExtendsIteratorAggregate iterable? bool(false)
Is IteratorImpl iterable? bool(true)
Is IteratorAggregateImpl iterable? bool(true)
Is ExtendsIteratorImpl iterable? bool(true)
Is ExtendsIteratorAggregateImpl iterable? bool(true)
Is A iterable? bool(false)
Test static invocation:
Fatal error: Uncaught Error: Non-static method ReflectionClass::isIterateable() cannot be called statically in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d