Skip to content

Commit

Permalink
Forbid multiple readonly modifiers
Browse files Browse the repository at this point in the history
Same as for other modifiers.
  • Loading branch information
nikic committed Jul 21, 2021
1 parent 4a8efc3 commit 11b990f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Zend/tests/readonly_props/multiple_modifiers.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Cannot use multiple readonly modifiers
--FILE--
<?php

class Test {
readonly readonly int $prop;
}

?>
--EXPECTF--
Fatal error: Multiple readonly modifiers are not allowed 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 @@ -823,6 +823,11 @@ uint32_t zend_add_member_modifier(uint32_t flags, uint32_t new_flag) /* {{{ */
zend_throw_exception(zend_ce_compile_error, "Multiple final modifiers are not allowed", 0);
return 0;
}
if ((flags & ZEND_ACC_READONLY) && (new_flag & ZEND_ACC_READONLY)) {
zend_throw_exception(zend_ce_compile_error,
"Multiple readonly modifiers are not allowed", 0);
return 0;
}
if ((new_flags & ZEND_ACC_ABSTRACT) && (new_flags & ZEND_ACC_FINAL)) {
zend_throw_exception(zend_ce_compile_error,
"Cannot use the final modifier on an abstract class member", 0);
Expand Down

0 comments on commit 11b990f

Please sign in to comment.