Skip to content

Commit 980bd0e

Browse files
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-20377: emit assignment for all final promoted properties (#20378)
2 parents 20bc059 + e5c6456 commit 980bd0e

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-20377: Constructor promotion with a final property without visibility set
3+
--FILE--
4+
<?php
5+
6+
class Demo {
7+
public function __construct(
8+
final string $foo,
9+
final public string $bar,
10+
) {}
11+
}
12+
13+
$d = new Demo("first", "second");
14+
var_dump($d);
15+
16+
?>
17+
--EXPECTF--
18+
object(Demo)#%d (2) {
19+
["foo"]=>
20+
string(5) "first"
21+
["bar"]=>
22+
string(6) "second"
23+
}

Zend/zend_compile.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7864,6 +7864,7 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
78647864
}
78657865
}
78667866

7867+
const uint32_t promotion_flags = ZEND_ACC_PPP_MASK | ZEND_ACC_PPP_SET_MASK | ZEND_ACC_READONLY | ZEND_ACC_FINAL;
78677868
for (i = 0; i < list->children; ++i) {
78687869
zend_ast *param_ast = list->child[i];
78697870
zend_ast *type_ast = param_ast->child[0];
@@ -7875,7 +7876,7 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
78757876
zend_string *name = zval_make_interned_string(zend_ast_get_zval(var_ast));
78767877
bool is_ref = (param_ast->attr & ZEND_PARAM_REF) != 0;
78777878
bool is_variadic = (param_ast->attr & ZEND_PARAM_VARIADIC) != 0;
7878-
uint32_t property_flags = param_ast->attr & (ZEND_ACC_PPP_MASK | ZEND_ACC_PPP_SET_MASK | ZEND_ACC_READONLY | ZEND_ACC_FINAL);
7879+
uint32_t property_flags = param_ast->attr & promotion_flags;
78797880
bool is_promoted = property_flags || hooks_ast;
78807881

78817882
CG(zend_lineno) = param_ast->lineno;
@@ -8102,7 +8103,7 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
81028103
zend_ast *param_ast = list->child[i];
81038104
zend_ast *hooks_ast = param_ast->child[5];
81048105
bool is_ref = (param_ast->attr & ZEND_PARAM_REF) != 0;
8105-
uint32_t flags = param_ast->attr & (ZEND_ACC_PPP_MASK | ZEND_ACC_PPP_SET_MASK | ZEND_ACC_READONLY);
8106+
uint32_t flags = param_ast->attr & promotion_flags;
81068107
bool is_promoted = flags || hooks_ast;
81078108
if (!is_promoted) {
81088109
continue;

0 commit comments

Comments
 (0)