Skip to content

Commit

Permalink
Validate that promoted readonly properties have a type
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Jul 25, 2021
1 parent 8d25b62 commit 3babe95
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Zend/tests/readonly_props/promotion_error1.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Promoted readonly property must have type
--FILE--
<?php

class Foo {
public function __construct(
public readonly $bar
) {}
}

?>
--EXPECTF--
Fatal error: Readonly property Foo::$bar must have type in %s on line %d
5 changes: 5 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -6774,6 +6774,11 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
if (ZEND_TYPE_IS_SET(type)) {
ZVAL_UNDEF(&default_value);
} else {
if (property_flags & ZEND_ACC_READONLY) {
zend_error_noreturn(E_COMPILE_ERROR, "Readonly property %s::$%s must have type",
ZSTR_VAL(scope->name), ZSTR_VAL(name));
}

ZVAL_NULL(&default_value);
}

Expand Down

0 comments on commit 3babe95

Please sign in to comment.