1--TEST-- 2exit(false); 3--FILE-- 4<?php 5 6function zend_test_var_export($value) { 7 if ($value === PHP_INT_MIN) { 8 return "PHP_INT_MIN"; 9 } 10 if ($value === PHP_INT_MAX) { 11 return "PHP_INT_MAX"; 12 } 13 if (is_array($value)) { 14 return "[]"; 15 } 16 if (is_resource($value)) { 17 return "STDERR"; 18 } 19 if ($value instanceof stdClass) { 20 return "new stdClass()"; 21 } 22 return var_export($value, true); 23} 24 25$values = [ 26 null, 27 false, 28 true, 29 0, 30 1, 31 20, 32 10.0, 33 15.5, 34 "Hello world", 35 [], 36 STDERR, 37 new stdClass(), 38]; 39 40const FILE_PATH = __DIR__ . '/exit_values_test.php'; 41const FILE_CONTENT = <<<'TEMPLATE' 42<?php 43try { 44 exit(VALUE); 45} catch (\Throwable $e) { 46 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 47} 48 49TEMPLATE; 50 51$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); 52$command = $php . ' --no-php-ini ' . escapeshellarg(FILE_PATH); 53 54foreach ([FILE_CONTENT, str_replace('exit', 'die', FILE_CONTENT)] as $code) { 55 foreach ($values as $value) { 56 echo 'Using ', zend_test_var_export($value), ' as value:', PHP_EOL; 57 $output = []; 58 $content = str_replace('VALUE', zend_test_var_export($value), $code); 59 file_put_contents(FILE_PATH, $content); 60 exec($command, $output, $exit_status); 61 echo 'Exit status is: ', $exit_status, PHP_EOL, 62 'Output is:', PHP_EOL, join($output), PHP_EOL; 63 } 64 65 echo 'As a statement:', PHP_EOL; 66 $output = []; 67 $content = str_replace('(VALUE)', '', $code); 68 exec($command, $output, $exit_status); 69 echo 'Exit status is: ', $exit_status, PHP_EOL, 70 'Output is:', PHP_EOL, join($output), PHP_EOL; 71} 72 73?> 74--CLEAN-- 75<?php 76const FILE_PATH = __DIR__ . '/exit_values_test.php'; 77@unlink(FILE_PATH); 78?> 79--EXPECTF-- 80Using NULL as value: 81Exit status is: 0 82Output is: 83Deprecated: exit(): Passing null to parameter #1 ($status) of type string|int is deprecated in %s on line %d 84Using false as value: 85Exit status is: 0 86Output is: 87 88Using true as value: 89Exit status is: 1 90Output is: 91 92Using 0 as value: 93Exit status is: 0 94Output is: 95 96Using 1 as value: 97Exit status is: 1 98Output is: 99 100Using 20 as value: 101Exit status is: 20 102Output is: 103 104Using 10.0 as value: 105Exit status is: 10 106Output is: 107 108Using 15.5 as value: 109Exit status is: 15 110Output is: 111Deprecated: Implicit conversion from float 15.5 to int loses precision in %s on line %d 112Using 'Hello world' as value: 113Exit status is: 0 114Output is: 115Hello world 116Using [] as value: 117Exit status is: 0 118Output is: 119TypeError: exit(): Argument #1 ($status) must be of type string|int, array given 120Using STDERR as value: 121Exit status is: 0 122Output is: 123TypeError: exit(): Argument #1 ($status) must be of type string|int, resource given 124Using new stdClass() as value: 125Exit status is: 0 126Output is: 127TypeError: exit(): Argument #1 ($status) must be of type string|int, stdClass given 128As a statement: 129Exit status is: 0 130Output is: 131TypeError: exit(): Argument #1 ($status) must be of type string|int, stdClass given 132Using NULL as value: 133Exit status is: 0 134Output is: 135Deprecated: exit(): Passing null to parameter #1 ($status) of type string|int is deprecated in %s on line %d 136Using false as value: 137Exit status is: 0 138Output is: 139 140Using true as value: 141Exit status is: 1 142Output is: 143 144Using 0 as value: 145Exit status is: 0 146Output is: 147 148Using 1 as value: 149Exit status is: 1 150Output is: 151 152Using 20 as value: 153Exit status is: 20 154Output is: 155 156Using 10.0 as value: 157Exit status is: 10 158Output is: 159 160Using 15.5 as value: 161Exit status is: 15 162Output is: 163Deprecated: Implicit conversion from float 15.5 to int loses precision in %s on line %d 164Using 'Hello world' as value: 165Exit status is: 0 166Output is: 167Hello world 168Using [] as value: 169Exit status is: 0 170Output is: 171TypeError: exit(): Argument #1 ($status) must be of type string|int, array given 172Using STDERR as value: 173Exit status is: 0 174Output is: 175TypeError: exit(): Argument #1 ($status) must be of type string|int, resource given 176Using new stdClass() as value: 177Exit status is: 0 178Output is: 179TypeError: exit(): Argument #1 ($status) must be of type string|int, stdClass given 180As a statement: 181Exit status is: 0 182Output is: 183TypeError: exit(): Argument #1 ($status) must be of type string|int, stdClass given 184