mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Fix GH-20217: ReflectionClass::isIterable() should return false for classes with property hooks (#20241)
This commit is contained in:
committed by
GitHub
parent
913327d1fb
commit
572652e5de
4
NEWS
4
NEWS
@@ -67,6 +67,10 @@ PHP NEWS
|
||||
- Random:
|
||||
. Fix Randomizer::__serialize() w.r.t. INDIRECTs. (nielsdos)
|
||||
|
||||
- Reflection:
|
||||
. Fixed bug GH-20217 (ReflectionClass::isIterable() incorrectly returns true
|
||||
for classes with property hooks). (alexandre-daubois)
|
||||
|
||||
- SimpleXML:
|
||||
. Partially fixed bug GH-16317 (SimpleXML does not allow __debugInfo() overrides
|
||||
to work). (nielsdos)
|
||||
|
||||
@@ -5696,7 +5696,8 @@ ZEND_METHOD(ReflectionClass, isIterable)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_BOOL(ce->get_iterator || instanceof_function(ce, zend_ce_traversable));
|
||||
RETURN_BOOL((ce->get_iterator && ce->get_iterator != zend_hooked_object_get_iterator)
|
||||
|| instanceof_function(ce, zend_ce_traversable));
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
38
ext/reflection/tests/ReflectionClass_isIterable_gh20217.phpt
Normal file
38
ext/reflection/tests/ReflectionClass_isIterable_gh20217.phpt
Normal file
@@ -0,0 +1,38 @@
|
||||
--TEST--
|
||||
GH-20217 (ReflectionClass::isIterable() should return false for classes with property hooks)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class ClassWithPropertyHooks
|
||||
{
|
||||
public string $name {
|
||||
get => 'virtual';
|
||||
}
|
||||
}
|
||||
|
||||
class IterableClassWithPropertyHooks implements IteratorAggregate
|
||||
{
|
||||
public string $name {
|
||||
get => 'virtual';
|
||||
}
|
||||
|
||||
public function getIterator(): Traversable
|
||||
{
|
||||
return new ArrayIterator([]);
|
||||
}
|
||||
}
|
||||
|
||||
$classes = [
|
||||
'ClassWithPropertyHooks' => false,
|
||||
'IterableClassWithPropertyHooks' => true,
|
||||
];
|
||||
|
||||
foreach ($classes as $className => $expected) {
|
||||
$status = (new ReflectionClass($className)->isIterable() === $expected) ? 'PASS' : 'FAIL';
|
||||
echo "$className: $status\n";
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
ClassWithPropertyHooks: PASS
|
||||
IterableClassWithPropertyHooks: PASS
|
||||
Reference in New Issue
Block a user