-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHP 8.4 | Exit as function: fix incorrect parameter name (#15433)
Follow up on 13483 As previously reported in #13483 (comment): > The parameter names seem to be incorrect. > > It should be `$status`, not `$code`. > > The RFC explicitly uses that parameter name in the proposal: https://wiki.php.net/rfc/exit-as-function#proposal > > It is also the name already used in the [manual](https://www.php.net/exit). > > Lastly, the parameter name `$status` better covers what can be passed: either a status _message_ or a status _code_. > While `$code` would read pretty weird when passing a message: > ```php > exit(code: 'message'); > ``` This commit attempts to fix this. Includes adding a test for exit/die using a named argument. Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
- Loading branch information
Showing
7 changed files
with
79 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.