Skip to content

PHP 8.4 | Exit as function: fix incorrect parameter name #15433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Zend/tests/exit/die_string_cast_exception.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ try {

?>
--EXPECT--
exit(): Argument #1 ($code) must be of type string|int, stdClass given
exit(): Argument #1 ($status) must be of type string|int, stdClass given
4 changes: 2 additions & 2 deletions Zend/tests/exit/exit_as_function.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object(Closure)#1 (2) {
string(4) "exit"
["parameter"]=>
array(1) {
["$code"]=>
["$status"]=>
string(10) "<optional>"
}
}
Expand All @@ -36,7 +36,7 @@ object(Closure)#2 (2) {
string(4) "exit"
["parameter"]=>
array(1) {
["$code"]=>
["$status"]=>
string(10) "<optional>"
}
}
59 changes: 59 additions & 0 deletions Zend/tests/exit/exit_named_arg.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
--TEST--
Using exit()/die() as function call with a named argument
--FILE--
<?php

$values = [
12,
"Goodbye!",
];

const FILE_PATH = __DIR__ . '/exit_named_arg_test.php';
const FILE_CONTENT = <<<'TEMPLATE'
<?php
try {
exit(status: VALUE);
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

TEMPLATE;

$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
$command = $php . ' --no-php-ini ' . escapeshellarg(FILE_PATH);

foreach ([FILE_CONTENT, str_replace('exit', 'die', FILE_CONTENT)] as $code) {
foreach ($values as $value) {
echo 'Using ', var_export($value, true), ' as value:', PHP_EOL;
$output = [];
$content = str_replace('VALUE', var_export($value, true), $code);
file_put_contents(FILE_PATH, $content);
exec($command, $output, $exit_status);
echo 'Exit status is: ', $exit_status, PHP_EOL,
'Output is:', PHP_EOL, join($output), PHP_EOL;
}
}

?>
--CLEAN--
<?php
const FILE_PATH = __DIR__ . '/exit_named_arg_test.php';
@unlink(FILE_PATH);
?>
--EXPECT--
Using 12 as value:
Exit status is: 12
Output is:

Using 'Goodbye!' as value:
Exit status is: 0
Output is:
Goodbye!
Using 12 as value:
Exit status is: 12
Output is:

Using 'Goodbye!' as value:
Exit status is: 0
Output is:
Goodbye!
20 changes: 10 additions & 10 deletions Zend/tests/exit/exit_values.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const FILE_PATH = __DIR__ . '/exit_values_test.php';
Using NULL as value:
Exit status is: 0
Output is:
Deprecated: exit(): Passing null to parameter #1 ($code) of type string|int is deprecated in %s on line %d
Deprecated: exit(): Passing null to parameter #1 ($status) of type string|int is deprecated in %s on line %d
Using false as value:
Exit status is: 0
Output is:
Expand Down Expand Up @@ -116,23 +116,23 @@ Hello world
Using [] as value:
Exit status is: 0
Output is:
TypeError: exit(): Argument #1 ($code) must be of type string|int, array given
TypeError: exit(): Argument #1 ($status) must be of type string|int, array given
Using STDERR as value:
Exit status is: 0
Output is:
TypeError: exit(): Argument #1 ($code) must be of type string|int, resource given
TypeError: exit(): Argument #1 ($status) must be of type string|int, resource given
Using new stdClass() as value:
Exit status is: 0
Output is:
TypeError: exit(): Argument #1 ($code) must be of type string|int, stdClass given
TypeError: exit(): Argument #1 ($status) must be of type string|int, stdClass given
As a statement:
Exit status is: 0
Output is:
TypeError: exit(): Argument #1 ($code) must be of type string|int, stdClass given
TypeError: exit(): Argument #1 ($status) must be of type string|int, stdClass given
Using NULL as value:
Exit status is: 0
Output is:
Deprecated: exit(): Passing null to parameter #1 ($code) of type string|int is deprecated in %s on line %d
Deprecated: exit(): Passing null to parameter #1 ($status) of type string|int is deprecated in %s on line %d
Using false as value:
Exit status is: 0
Output is:
Expand Down Expand Up @@ -168,16 +168,16 @@ Hello world
Using [] as value:
Exit status is: 0
Output is:
TypeError: exit(): Argument #1 ($code) must be of type string|int, array given
TypeError: exit(): Argument #1 ($status) must be of type string|int, array given
Using STDERR as value:
Exit status is: 0
Output is:
TypeError: exit(): Argument #1 ($code) must be of type string|int, resource given
TypeError: exit(): Argument #1 ($status) must be of type string|int, resource given
Using new stdClass() as value:
Exit status is: 0
Output is:
TypeError: exit(): Argument #1 ($code) must be of type string|int, stdClass given
TypeError: exit(): Argument #1 ($status) must be of type string|int, stdClass given
As a statement:
Exit status is: 0
Output is:
TypeError: exit(): Argument #1 ($code) must be of type string|int, stdClass given
TypeError: exit(): Argument #1 ($status) must be of type string|int, stdClass given
6 changes: 3 additions & 3 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ zend_result zend_startup_builtin_functions(void) /* {{{ */
ZEND_FUNCTION(exit)
{
zend_string *str = NULL;
zend_long code = 0;
zend_long status = 0;

ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_STR_OR_LONG(str, code)
Z_PARAM_STR_OR_LONG(str, status)
ZEND_PARSE_PARAMETERS_END();

if (str) {
Expand All @@ -89,7 +89,7 @@ ZEND_FUNCTION(exit)
}
}
} else {
EG(exit_status) = code;
EG(exit_status) = status;
}

ZEND_ASSERT(!EG(exception));
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_builtin_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class stdClass
{
}

function exit(string|int $code = 0): never {}
function exit(string|int $status = 0): never {}

/** @alias exit */
function die(string|int $code = 0): never {}
function die(string|int $status = 0): never {}

/** @refcount 1 */
function zend_version(): string {}
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_builtin_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading