1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.5'

* PHP-8.5:
  Fix GH-20217: ReflectionClass::isIterable() should return false for classes with property hooks (#20241)
This commit is contained in:
Alexandre Daubois
2025-10-22 10:04:02 +02:00
3 changed files with 44 additions and 1 deletions

4
NEWS
View File

@@ -25,6 +25,10 @@ PHP NEWS
. Invalid values now throw in Phar::mungServer() instead of being silently
ignored. (nielsdos)
- Reflection:
. Fixed bug GH-20217 (ReflectionClass::isIterable() incorrectly returns true
for classes with property hooks). (alexandre-daubois)
- Standard:
. Fixed bug GH-19926 (reset internal pointer earlier while splicing array
while COW violation flag is still set). (alexandre-daubois)

View File

@@ -5589,7 +5589,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));
}
/* }}} */

View 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