Skip to content

Commit 39d5cbb

Browse files
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix phpGH-20217: ReflectionClass::isIterable() should return false for classes with property hooks (php#20241)
2 parents 920847e + 572652e commit 39d5cbb

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.5.0RC4
44

5+
- Reflection:
6+
. Fixed bug GH-20217 (ReflectionClass::isIterable() incorrectly returns true
7+
for classes with property hooks). (alexandre-daubois)
58

69
23 Oct 2025, PHP 8.5.0RC3
710

ext/reflection/php_reflection.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5589,7 +5589,8 @@ ZEND_METHOD(ReflectionClass, isIterable)
55895589
RETURN_FALSE;
55905590
}
55915591

5592-
RETURN_BOOL(ce->get_iterator || instanceof_function(ce, zend_ce_traversable));
5592+
RETURN_BOOL((ce->get_iterator && ce->get_iterator != zend_hooked_object_get_iterator)
5593+
|| instanceof_function(ce, zend_ce_traversable));
55935594
}
55945595
/* }}} */
55955596

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
GH-20217 (ReflectionClass::isIterable() should return false for classes with property hooks)
3+
--FILE--
4+
<?php
5+
6+
class ClassWithPropertyHooks
7+
{
8+
public string $name {
9+
get => 'virtual';
10+
}
11+
}
12+
13+
class IterableClassWithPropertyHooks implements IteratorAggregate
14+
{
15+
public string $name {
16+
get => 'virtual';
17+
}
18+
19+
public function getIterator(): Traversable
20+
{
21+
return new ArrayIterator([]);
22+
}
23+
}
24+
25+
$classes = [
26+
'ClassWithPropertyHooks' => false,
27+
'IterableClassWithPropertyHooks' => true,
28+
];
29+
30+
foreach ($classes as $className => $expected) {
31+
$status = (new ReflectionClass($className)->isIterable() === $expected) ? 'PASS' : 'FAIL';
32+
echo "$className: $status\n";
33+
}
34+
35+
?>
36+
--EXPECT--
37+
ClassWithPropertyHooks: PASS
38+
IterableClassWithPropertyHooks: PASS

0 commit comments

Comments
 (0)