Skip to content

Commit 3babe95

Browse files
committed
Validate that promoted readonly properties have a type
1 parent 8d25b62 commit 3babe95

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Promoted readonly property must have type
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
public function __construct(
8+
public readonly $bar
9+
) {}
10+
}
11+
12+
?>
13+
--EXPECTF--
14+
Fatal error: Readonly property Foo::$bar must have type in %s on line %d

Zend/zend_compile.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6774,6 +6774,11 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
67746774
if (ZEND_TYPE_IS_SET(type)) {
67756775
ZVAL_UNDEF(&default_value);
67766776
} else {
6777+
if (property_flags & ZEND_ACC_READONLY) {
6778+
zend_error_noreturn(E_COMPILE_ERROR, "Readonly property %s::$%s must have type",
6779+
ZSTR_VAL(scope->name), ZSTR_VAL(name));
6780+
}
6781+
67776782
ZVAL_NULL(&default_value);
67786783
}
67796784

0 commit comments

Comments
 (0)