1--TEST--
2Using exit/die as a statement/constant
3--FILE--
4<?php
5
6const FILE_PATH = __DIR__ . '/exit_statements.php';
7const FILE_CONTENT = <<<'TEMPLATE'
8<?php
9echo "Before FUNCTION";
10try {
11    FUNCTION;
12} catch (\Throwable $e) {
13    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
14}
15
16TEMPLATE;
17
18
19$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
20$command = $php . ' ' . escapeshellarg(FILE_PATH);
21
22foreach (['exit', 'die'] as $value) {
23    echo 'Using ', $value, ' as value:', PHP_EOL;
24    $output = [];
25    $content = str_replace('FUNCTION', $value, FILE_CONTENT);
26    file_put_contents(FILE_PATH, $content);
27    exec($command, $output, $exit_status);
28    echo 'Exit status is: ', $exit_status, PHP_EOL,
29         'Output is:', PHP_EOL, join($output), PHP_EOL;
30}
31
32?>
33--CLEAN--
34<?php
35const FILE_PATH = __DIR__ . '/exit_statements.php';
36@unlink(FILE_PATH);
37?>
38--EXPECT--
39Using exit as value:
40Exit status is: 0
41Output is:
42Before exit
43Using die as value:
44Exit status is: 0
45Output is:
46Before die
47