Skip to content

Commit 512fee9

Browse files
committed
Disallow mutating keyword outside of data classes
1 parent 629a29b commit 512fee9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Mutating keyword in ordinary class
3+
--FILE--
4+
<?php
5+
6+
class Point {
7+
public mutating function zero() {}
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Mutating modifier may only be added to data class methods in %s on line %d

Zend/zend_compile.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7776,6 +7776,9 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
77767776
if (is_method) {
77777777
bool has_body = stmt_ast != NULL;
77787778
lcname = zend_begin_method_decl(op_array, decl->name, has_body);
7779+
if ((op_array->fn_flags & ZEND_ACC_MUTATING) && !(op_array->scope->ce_flags & ZEND_ACC_DATA_CLASS)) {
7780+
zend_error_noreturn(E_COMPILE_ERROR, "Mutating modifier may only be added to data class methods");
7781+
}
77797782
} else {
77807783
lcname = zend_begin_func_decl(result, op_array, decl, toplevel);
77817784
if (decl->kind == ZEND_AST_ARROW_FUNC) {

0 commit comments

Comments
 (0)