Skip to content

Commit ffe9d5b

Browse files
committed
Fix GH-23842: skipLazyInitialization() copies unresolved constant defaults
1 parent 7d4f779 commit ffe9d5b

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎NEWS‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ PHP NEWS
6464
. Fixed a heap over-read in the interactive shell prompt when cli.prompt is
6565
set to an empty string. (Ilia Alshanetsky)
6666

67+
- Reflection:
68+
. Fixed bug GH-23842 (ReflectionProperty::skipLazyInitialization() copies an
69+
unresolved constant default with opcache). (Lazizbek Ergashev)
70+
6771
- Sockets:
6872
. Fixed socket_select() silently truncating sets larger than FD_SETSIZE on
6973
Windows. (David Carlier)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
GH-23842: skipLazyInitialization() copies an unresolved constant default with opcache
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable=1
7+
opcache.enable_cli=1
8+
--FILE--
9+
<?php
10+
11+
class Currency {
12+
public const string EUR = 'EUR';
13+
}
14+
15+
class Product {
16+
public string $currency = Currency::EUR;
17+
}
18+
19+
$reflector = new ReflectionClass(Product::class);
20+
$product = $reflector->newLazyGhost(function () {
21+
throw new \Exception('initializer');
22+
});
23+
$reflector->getProperty('currency')->skipLazyInitialization($product);
24+
25+
var_dump($product->currency);
26+
27+
?>
28+
--EXPECT--
29+
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)