Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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)
Expand Down
3 changes: 2 additions & 1 deletion ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
/* }}} */

Expand Down
38 changes: 38 additions & 0 deletions ext/reflection/tests/ReflectionClass_isIterable_gh20217.phpt
Original file line number Diff line number Diff line change
@@ -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