Skip to content

Commit e0eea65

Browse files
lazergndossche
authored andcommitted
Fix GH-23842: skipLazyInitialization() copies unresolved constant defaults
Closes GH-23843.
1 parent efb8ad2 commit e0eea65

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ PHP NEWS
404404
parent slot when a child class hooks an inherited property. (iliaal)
405405
. Fixed segfault in ReflectionMethod::createFromMethodName() on an
406406
uninstantiable subclass. (iliaal)
407+
. Fixed bug GH-23842 (ReflectionProperty::skipLazyInitialization() copies
408+
invalid constant defaults with OPcache). (DirkTrunkstar, Lazizbek Ergashev)
407409

408410
- Readline:
409411
. Fixed class constant completion in the interactive shell. (Weilin Du)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
GH-23842: skipLazyInitialization() copies an unresolved constant default with opcache
3+
--CREDITS--
4+
DirkTrunkstar
5+
--EXTENSIONS--
6+
opcache
7+
--INI--
8+
opcache.enable=1
9+
opcache.enable_cli=1
10+
opcache.file_cache_only=0
11+
--FILE--
12+
<?php
13+
14+
class Currency {
15+
public const string EUR = 'EUR';
16+
}
17+
18+
class Product {
19+
public string $currency = Currency::EUR;
20+
}
21+
22+
$reflector = new ReflectionClass(Product::class);
23+
$product = $reflector->newLazyGhost(function () {
24+
throw new \Exception('initializer');
25+
});
26+
$reflector->getProperty('currency')->skipLazyInitialization($product);
27+
28+
var_dump($product->currency);
29+
30+
?>
31+
--EXPECT--
32+
string(3) "EUR"

‎ext/reflection/php_reflection.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6461,7 +6461,7 @@ ZEND_METHOD(ReflectionProperty, skipLazyInitialization)
64616461
RETURN_THROWS();
64626462
}
64636463

6464-
zval *src = &object->ce->default_properties_table[OBJ_PROP_TO_NUM(prop->offset)];
6464+
zval *src = &CE_DEFAULT_PROPERTIES_TABLE(object->ce)[OBJ_PROP_TO_NUM(prop->offset)];
64656465
zval *dst = OBJ_PROP(object, prop->offset);
64666466

64676467
if (!(Z_PROP_FLAG_P(dst) & IS_PROP_LAZY)) {

0 commit comments

Comments
 (0)