Skip to content

Commit 40751f0

Browse files
committed
Implement with parser approach
1 parent 04c54f3 commit 40751f0

25 files changed

+56
-80
lines changed

Zend/tests/exit/ast_print_assert_die_const.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ try {
1313

1414
?>
1515
--EXPECT--
16-
AssertionError: assert(0 && die)
16+
AssertionError: assert(0 && \exit())

Zend/tests/exit/ast_print_assert_die_function.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ try {
1313

1414
?>
1515
--EXPECT--
16-
AssertionError: assert(0 && die())
16+
AssertionError: assert(0 && \exit())

Zend/tests/exit/ast_print_assert_exit_const.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ try {
1313

1414
?>
1515
--EXPECT--
16-
AssertionError: assert(0 && exit)
16+
AssertionError: assert(0 && \exit())

Zend/tests/exit/ast_print_assert_exit_function.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ try {
1313

1414
?>
1515
--EXPECT--
16-
AssertionError: assert(0 && exit())
16+
AssertionError: assert(0 && \exit())

Zend/tests/exit/define_die_constant.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ var_dump(die);
99

1010
?>
1111
--EXPECTF--
12-
Fatal error: Cannot define constant with name die in %s on line %d
12+
Parse error: syntax error, unexpected token "exit", expecting identifier in %s on line %d

Zend/tests/exit/define_die_constant_namespace.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ var_dump(die);
1111

1212
?>
1313
--EXPECTF--
14-
Fatal error: Cannot define constant with name die in %s on line %d
14+
Parse error: syntax error, unexpected token "exit", expecting identifier in %s on line %d

Zend/tests/exit/define_die_function.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ function die() { }
77

88
?>
99
--EXPECTF--
10-
Fatal error: Defining a custom die() function is not allowed, as the function has special semantics in %s on line %d
10+
Parse error: syntax error, unexpected token "exit", expecting "(" in %s on line %d

Zend/tests/exit/define_die_function_namespace.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ var_dump(die());
1111

1212
?>
1313
--EXPECTF--
14-
Fatal error: Defining a custom die() function is not allowed, as the function has special semantics in %s on line %d
14+
Parse error: syntax error, unexpected token "exit", expecting "(" in %s on line %d

Zend/tests/exit/define_exit_constant.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ var_dump(exit);
99

1010
?>
1111
--EXPECTF--
12-
Fatal error: Cannot define constant with name exit in %s on line %d
12+
Parse error: syntax error, unexpected token "exit", expecting identifier in %s on line %d

Zend/tests/exit/define_exit_constant_namespace.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ var_dump(exit);
1111

1212
?>
1313
--EXPECTF--
14-
Fatal error: Cannot define constant with name exit in %s on line %d
14+
Parse error: syntax error, unexpected token "exit", expecting identifier in %s on line %d

Zend/tests/exit/define_exit_function.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ function exit() { }
77

88
?>
99
--EXPECTF--
10-
Fatal error: Defining a custom exit() function is not allowed, as the function has special semantics in %s on line %d
10+
Parse error: syntax error, unexpected token "exit", expecting "(" in %s on line %d

Zend/tests/exit/define_exit_function_namespace.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ function exit() { }
99

1010
?>
1111
--EXPECTF--
12-
Fatal error: Defining a custom exit() function is not allowed, as the function has special semantics in %s on line %d
12+
Parse error: syntax error, unexpected token "exit", expecting "(" in %s on line %d

Zend/tests/exit/define_goto_label_die.phpt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,5 @@ die:
1010
echo "After\n";
1111

1212
?>
13-
--EXPECT--
14-
Before
15-
In between
16-
After
13+
--EXPECTF--
14+
Parse error: syntax error, unexpected token ":" in %s on line %d

Zend/tests/exit/define_goto_label_die_with_jump.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ die:
1010
echo "After\n";
1111

1212
?>
13-
--EXPECT--
14-
Before
15-
After
13+
--EXPECTF--
14+
Parse error: syntax error, unexpected token "exit", expecting identifier in %s on line %d

Zend/tests/exit/define_goto_label_exit.phpt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,5 @@ exit:
1010
echo "After\n";
1111

1212
?>
13-
--EXPECT--
14-
Before
15-
In between
16-
After
13+
--EXPECTF--
14+
Parse error: syntax error, unexpected token ":" in %s on line %d

Zend/tests/exit/define_goto_label_exit_with_jump.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ exit:
1010
echo "After\n";
1111

1212
?>
13-
--EXPECT--
14-
Before
15-
After
13+
--EXPECTF--
14+
Parse error: syntax error, unexpected token "exit", expecting identifier in %s on line %d

Zend/tests/exit/die_string_cast_exception.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ try {
1111

1212
?>
1313
--EXPECT--
14-
die(): Argument #1 ($code) must be of type string|int, stdClass given
14+
exit(): Argument #1 ($code) must be of type string|int, stdClass given

Zend/tests/exit/exit_as_function.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ foreach ($values as $value) {
1919
}
2020

2121
?>
22-
--EXPECT--
22+
--EXPECTF--
2323
string(4) "exit"
2424
string(3) "die"
25-
object(Closure)#1 (2) {
25+
object(Closure)#%d (2) {
2626
["function"]=>
2727
string(4) "exit"
2828
["parameter"]=>
@@ -31,9 +31,9 @@ object(Closure)#1 (2) {
3131
string(10) "<optional>"
3232
}
3333
}
34-
object(Closure)#2 (2) {
34+
object(Closure)#%d (2) {
3535
["function"]=>
36-
string(3) "die"
36+
string(4) "exit"
3737
["parameter"]=>
3838
array(1) {
3939
["$code"]=>

Zend/tests/exit/exit_values.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ TypeError: exit(): Argument #1 ($code) must be of type string|int, stdClass give
132132
Using NULL as value:
133133
Exit status is: 0
134134
Output is:
135-
Deprecated: die(): Passing null to parameter #1 ($code) of type string|int is deprecated in %s on line %d
135+
Deprecated: exit(): Passing null to parameter #1 ($code) of type string|int is deprecated in %s on line %d
136136
Using false as value:
137137
Exit status is: 0
138138
Output is:
@@ -168,16 +168,16 @@ Hello world
168168
Using [] as value:
169169
Exit status is: 0
170170
Output is:
171-
TypeError: die(): Argument #1 ($code) must be of type string|int, array given
171+
TypeError: exit(): Argument #1 ($code) must be of type string|int, array given
172172
Using STDERR as value:
173173
Exit status is: 0
174174
Output is:
175-
TypeError: die(): Argument #1 ($code) must be of type string|int, resource given
175+
TypeError: exit(): Argument #1 ($code) must be of type string|int, resource given
176176
Using new stdClass() as value:
177177
Exit status is: 0
178178
Output is:
179-
TypeError: die(): Argument #1 ($code) must be of type string|int, stdClass given
179+
TypeError: exit(): Argument #1 ($code) must be of type string|int, stdClass given
180180
As a statement:
181181
Exit status is: 0
182182
Output is:
183-
TypeError: die(): Argument #1 ($code) must be of type string|int, stdClass given
183+
TypeError: exit(): Argument #1 ($code) must be of type string|int, stdClass given

Zend/zend_compile.c

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7764,14 +7764,10 @@ static zend_string *zend_begin_func_decl(znode *result, zend_op_array *op_array,
77647764
"__autoload() is no longer supported, use spl_autoload_register() instead");
77657765
}
77667766

7767-
if (
7768-
zend_string_equals_literal_ci(unqualified_name, "assert")
7769-
|| zend_string_equals_literal_ci(unqualified_name, "exit")
7770-
|| zend_string_equals_literal_ci(unqualified_name, "die")
7771-
) {
7767+
if (zend_string_equals_literal_ci(unqualified_name, "assert")) {
77727768
zend_error(E_COMPILE_ERROR,
7773-
"Defining a custom %s() function is not allowed, "
7774-
"as the function has special semantics", ZSTR_VAL(unqualified_name));
7769+
"Defining a custom assert() function is not allowed, "
7770+
"as the function has special semantics");
77757771
}
77767772

77777773
zend_register_seen_symbol(lcname, ZEND_SYMBOL_FUNCTION);
@@ -8714,13 +8710,6 @@ static void zend_compile_const_decl(zend_ast *ast) /* {{{ */
87148710
value_node.op_type = IS_CONST;
87158711
zend_const_expr_to_zval(value_zv, value_ast_ptr, /* allow_dynamic */ true);
87168712

8717-
if (UNEXPECTED(
8718-
zend_string_equals_literal_ci(unqualified_name, "exit")
8719-
|| zend_string_equals_literal_ci(unqualified_name, "die")
8720-
)) {
8721-
zend_throw_error(NULL, "Cannot define constant with name %s", ZSTR_VAL(unqualified_name));
8722-
return;
8723-
}
87248713
if (zend_get_special_const(ZSTR_VAL(unqualified_name), ZSTR_LEN(unqualified_name))) {
87258714
zend_error_noreturn(E_COMPILE_ERROR,
87268715
"Cannot redeclare constant '%s'", ZSTR_VAL(unqualified_name));
@@ -10016,34 +10005,6 @@ static void zend_compile_const(znode *result, zend_ast *ast) /* {{{ */
1001610005

1001710006
bool is_fully_qualified;
1001810007
zend_string *orig_name = zend_ast_get_str(name_ast);
10019-
10020-
/* The fake "constants" exit and die must be converted to a function call for exit() */
10021-
if (UNEXPECTED(
10022-
zend_string_equals_literal_ci(orig_name, "exit")
10023-
|| zend_string_equals_literal_ci(orig_name, "die")
10024-
)) {
10025-
zval *fbc_zv = zend_hash_find(CG(function_table), ZSTR_KNOWN(ZEND_STR_EXIT));
10026-
ZEND_ASSERT(fbc_zv && "exit() function should always exist");
10027-
zend_function *fbc = Z_PTR_P(fbc_zv);
10028-
10029-
znode name_node;
10030-
name_node.op_type = IS_CONST;
10031-
ZVAL_STR(&name_node.u.constant, ZSTR_KNOWN(ZEND_STR_EXIT));
10032-
10033-
opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, &name_node);
10034-
opline->result.num = zend_alloc_cache_slot();
10035-
10036-
/* Store offset to function from symbol table in op2.extra. */
10037-
{
10038-
Bucket *fbc_bucket = (Bucket*)((uintptr_t)fbc_zv - XtOffsetOf(Bucket, val));
10039-
Z_EXTRA_P(CT_CONSTANT(opline->op2)) = fbc_bucket - CG(function_table)->arData;
10040-
}
10041-
10042-
zend_ast *args_list = zend_ast_create_list_0(ZEND_AST_ARG_LIST);
10043-
zend_compile_call_common(result, args_list, fbc, ast->lineno);
10044-
return;
10045-
}
10046-
1004710008
zend_string *resolved_name = zend_resolve_const_name(orig_name, name_ast->attr, &is_fully_qualified);
1004810009

1004910010
if (zend_string_equals_literal(resolved_name, "__COMPILER_HALT_OFFSET__") || (name_ast->attr != ZEND_NAME_RELATIVE && zend_string_equals_literal(orig_name, "__COMPILER_HALT_OFFSET__"))) {

Zend/zend_language_parser.y

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
113113
%token <ident> T_INSTANCEOF "'instanceof'"
114114
%token <ident> T_NEW "'new'"
115115
%token <ident> T_CLONE "'clone'"
116+
%token <ident> T_EXIT "'exit'"
116117
%token <ident> T_IF "'if'"
117118
%token <ident> T_ELSEIF "'elseif'"
118119
%token <ident> T_ELSE "'else'"
@@ -296,7 +297,7 @@ start:
296297

297298
reserved_non_modifiers:
298299
T_INCLUDE | T_INCLUDE_ONCE | T_EVAL | T_REQUIRE | T_REQUIRE_ONCE | T_LOGICAL_OR | T_LOGICAL_XOR | T_LOGICAL_AND
299-
| T_INSTANCEOF | T_NEW | T_CLONE | T_IF | T_ELSEIF | T_ELSE | T_ENDIF | T_ECHO | T_DO | T_WHILE | T_ENDWHILE
300+
| T_INSTANCEOF | T_NEW | T_CLONE | T_EXIT | T_IF | T_ELSEIF | T_ELSE | T_ENDIF | T_ECHO | T_DO | T_WHILE | T_ENDWHILE
300301
| T_FOR | T_ENDFOR | T_FOREACH | T_ENDFOREACH | T_DECLARE | T_ENDDECLARE | T_AS | T_TRY | T_CATCH | T_FINALLY
301302
| T_THROW | T_USE | T_INSTEADOF | T_GLOBAL | T_VAR | T_UNSET | T_ISSET | T_EMPTY | T_CONTINUE | T_GOTO
302303
| T_FUNCTION | T_CONST | T_RETURN | T_PRINT | T_YIELD | T_LIST | T_SWITCH | T_ENDSWITCH | T_CASE | T_DEFAULT | T_BREAK
@@ -1239,6 +1240,11 @@ expr:
12391240
| T_OBJECT_CAST expr { $$ = zend_ast_create_cast(IS_OBJECT, $2); }
12401241
| T_BOOL_CAST expr { $$ = zend_ast_create_cast(_IS_BOOL, $2); }
12411242
| T_UNSET_CAST expr { $$ = zend_ast_create_cast(IS_NULL, $2); }
1243+
| T_EXIT ctor_arguments {
1244+
zend_ast *name = zend_ast_create_zval_from_str(ZSTR_KNOWN(ZEND_STR_EXIT));
1245+
name->attr = ZEND_NAME_FQ;
1246+
$$ = zend_ast_create(ZEND_AST_CALL, name, $2);
1247+
}
12421248
| '@' expr { $$ = zend_ast_create(ZEND_AST_SILENCE, $2); }
12431249
| scalar { $$ = $1; }
12441250
| '`' backticks_expr '`' { $$ = zend_ast_create(ZEND_AST_SHELL_EXEC, $2); }

Zend/zend_language_scanner.l

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,14 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
13821382
/* compute yyleng before each rule */
13831383
<!*> := yyleng = YYCURSOR - SCNG(yy_text);
13841384

1385+
<ST_IN_SCRIPTING>"exit" {
1386+
RETURN_TOKEN_WITH_IDENT(T_EXIT);
1387+
}
1388+
1389+
<ST_IN_SCRIPTING>"die" {
1390+
RETURN_TOKEN_WITH_IDENT(T_EXIT);
1391+
}
1392+
13851393
<ST_IN_SCRIPTING>"fn" {
13861394
RETURN_TOKEN_WITH_IDENT(T_FN);
13871395
}

ext/tokenizer/tokenizer_data.c

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/tokenizer/tokenizer_data.stub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@
132132
* @cvalue T_CLONE
133133
*/
134134
const T_CLONE = UNKNOWN;
135+
/**
136+
* @var int
137+
* @cvalue T_EXIT
138+
*/
139+
const T_EXIT = UNKNOWN;
135140
/**
136141
* @var int
137142
* @cvalue T_IF

ext/tokenizer/tokenizer_data_arginfo.h

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)