Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -6313,6 +6313,11 @@ static void zend_compile_switch(zend_ast *ast) /* {{{ */
continue;
}

if (case_ast->attr == ZEND_ALT_CASE_SYNTAX) {
CG(zend_lineno) = case_ast->lineno;
zend_error(E_DEPRECATED, "Case statements followed by a semicolon (;) are deprecated, use a colon (:) instead");
}

zend_compile_expr(&cond_node, cond_ast);

if (expr_node.op_type == IS_CONST
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,7 @@ ZEND_API zend_string *zend_type_to_string(zend_type type);
((ZEND_TYPE_FULL_MASK((arg_info)->type) & _ZEND_IS_TENTATIVE_BIT) != 0)

#define ZEND_DIM_IS (1 << 0) /* isset fetch needed for null coalesce. Set in zend_compile.c for ZEND_AST_DIM nested within ZEND_AST_COALESCE. */
#define ZEND_ALT_CASE_SYNTAX (1 << 1) /* deprecated switch case terminated by semicolon */

/* Attributes for ${} encaps var in strings (ZEND_AST_DIM or ZEND_AST_VAR node) */
/* ZEND_AST_VAR nodes can have any of the ZEND_ENCAPS_VAR_* flags */
Expand Down
13 changes: 6 additions & 7 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -713,15 +713,14 @@ switch_case_list:

case_list:
%empty { $$ = zend_ast_create_list(0, ZEND_AST_SWITCH_LIST); }
| case_list T_CASE expr case_separator inner_statement_list
| case_list T_CASE expr ':' inner_statement_list
{ $$ = zend_ast_list_add($1, zend_ast_create(ZEND_AST_SWITCH_CASE, $3, $5)); }
| case_list T_DEFAULT case_separator inner_statement_list
| case_list T_CASE expr ';' inner_statement_list
{ $$ = zend_ast_list_add($1, zend_ast_create_ex(ZEND_AST_SWITCH_CASE, ZEND_ALT_CASE_SYNTAX, $3, $5)); }
| case_list T_DEFAULT ':' inner_statement_list
{ $$ = zend_ast_list_add($1, zend_ast_create(ZEND_AST_SWITCH_CASE, NULL, $4)); }
;

case_separator:
':'
| ';'
| case_list T_DEFAULT ';' inner_statement_list
{ $$ = zend_ast_list_add($1, zend_ast_create_ex(ZEND_AST_SWITCH_CASE, ZEND_ALT_CASE_SYNTAX, NULL, $4)); }
;


Expand Down
4 changes: 2 additions & 2 deletions ext/opcache/tests/issue0057.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class ZException extends Exception {
function dummy($query) {
try {
switch ($query) {
case 1;
case 1:
break;
case 2;
case 2:
break;
default:
throw new Exception('exception');
Expand Down
3 changes: 2 additions & 1 deletion tests/lang/033.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ switch ($a):
break;
endswitch;
?>
--EXPECT--
--EXPECTF--
Deprecated: Case statements followed by a semicolon (;) are deprecated, use a colon (:) instead in %s
If: 11
While: 12346789
For: 0123401234
Expand Down
2 changes: 1 addition & 1 deletion tests/lang/bug26696.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ for ($i = 0; $i < $len; $i++) {

$str = '*';
switch ($str[0]) {
case '*';
case '*':
echo "OK\n";
break;
default:
Expand Down
Loading