xref: /PHP-8.4/Zend/tests/exit/exit_named_arg.phpt (revision 4c5767f6)
1--TEST--
2Using exit()/die() as function call with a named argument
3--FILE--
4<?php
5
6$values = [
7    12,
8    "Goodbye!",
9];
10
11const FILE_PATH = __DIR__ . '/exit_named_arg_test.php';
12const FILE_CONTENT = <<<'TEMPLATE'
13<?php
14try {
15    exit(status: VALUE);
16} catch (\Throwable $e) {
17    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
18}
19
20TEMPLATE;
21
22$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
23$command = $php . ' --no-php-ini ' . escapeshellarg(FILE_PATH);
24
25foreach ([FILE_CONTENT, str_replace('exit', 'die', FILE_CONTENT)] as $code) {
26    foreach ($values as $value) {
27        echo 'Using ', var_export($value, true), ' as value:', PHP_EOL;
28        $output = [];
29        $content = str_replace('VALUE', var_export($value, true), $code);
30        file_put_contents(FILE_PATH, $content);
31        exec($command, $output, $exit_status);
32        echo 'Exit status is: ', $exit_status, PHP_EOL,
33             'Output is:', PHP_EOL, join($output), PHP_EOL;
34    }
35}
36
37?>
38--CLEAN--
39<?php
40const FILE_PATH = __DIR__ . '/exit_named_arg_test.php';
41@unlink(FILE_PATH);
42?>
43--EXPECT--
44Using 12 as value:
45Exit status is: 12
46Output is:
47
48Using 'Goodbye!' as value:
49Exit status is: 0
50Output is:
51Goodbye!
52Using 12 as value:
53Exit status is: 12
54Output is:
55
56Using 'Goodbye!' as value:
57Exit status is: 0
58Output is:
59Goodbye!
60