Skip to content

Commit b6d7c01

Browse files
authored
Fix virtual properties in get_class_vars() (phpGH-15494)
Fixes phpGH-15456
1 parent 60f87f2 commit b6d7c01

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ PHP NEWS
1010
. Fixed bug GH-15419 (Missing readonly+hook incompatibility check for readonly
1111
classes). (ilutov)
1212
. Fixed bug GH-15187 (Various hooked object iterator issues). (ilutov)
13+
. Fixed bug GH-15456 (Crash in get_class_vars() on virtual properties).
14+
(ilutov)
1315

1416
15 Aug 2024, PHP 8.4.0beta3
1517

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-15456: Crash in get_class_vars() on virtual properties
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $a = 42;
8+
public $b = 42 { get => $this->b * 2; }
9+
public $c { get => 42; }
10+
}
11+
var_dump(get_class_vars(C::class));
12+
13+
?>
14+
--EXPECT--
15+
array(2) {
16+
["a"]=>
17+
int(42)
18+
["b"]=>
19+
int(42)
20+
}

Zend/zend_builtin_functions.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,8 @@ static void add_class_vars(zend_class_entry *scope, zend_class_entry *ce, bool s
724724
if (((prop_info->flags & ZEND_ACC_PROTECTED) &&
725725
!zend_check_protected(prop_info->ce, scope)) ||
726726
((prop_info->flags & ZEND_ACC_PRIVATE) &&
727-
prop_info->ce != scope)) {
727+
prop_info->ce != scope) ||
728+
(prop_info->flags & ZEND_ACC_VIRTUAL)) {
728729
continue;
729730
}
730731
prop = NULL;

0 commit comments

Comments
 (0)