Skip to content

Commit 206395f

Browse files
Merge branch 'PHP-8.5'
* PHP-8.5: Fix phpGH-20217: ReflectionClass::isIterable() should return false for classes with property hooks (php#20241)
2 parents 25de02b + 39d5cbb commit 206395f

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ PHP NEWS
2525
. Invalid values now throw in Phar::mungServer() instead of being silently
2626
ignored. (nielsdos)
2727

28+
- Reflection:
29+
. Fixed bug GH-20217 (ReflectionClass::isIterable() incorrectly returns true
30+
for classes with property hooks). (alexandre-daubois)
31+
2832
- Standard:
2933
. Fixed bug GH-19926 (reset internal pointer earlier while splicing array
3034
while COW violation flag is still set). (alexandre-daubois)

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)