Skip to content

Commit b476eca

Browse files
committed
Error on multiple default blocks in a switch
Part of RFC: https://wiki.php.net/rfc/switch.default.multiple
1 parent 7d0416f commit b476eca

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

Zend/tests/034.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ switch (1) {
2222
}
2323

2424
?>
25-
--EXPECT--
26-
3
25+
--EXPECTF--
26+
Fatal error: Switch statements may only contain one default clause in %s on line 13

Zend/zend_compile.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5091,6 +5091,11 @@ void zend_compile_switch(zend_ast *ast TSRMLS_DC) /* {{{ */
50915091
znode cond_node;
50925092

50935093
if (!cond_ast) {
5094+
if (has_default_case) {
5095+
CG(zend_lineno) = case_ast->lineno;
5096+
zend_error_noreturn(E_COMPILE_ERROR,
5097+
"Switch statements may only contain one default clause");
5098+
}
50945099
has_default_case = 1;
50955100
continue;
50965101
}

0 commit comments

Comments
 (0)