1--TEST-- 2Using proc_open() with a command array (no shell) 3--FILE-- 4<?php 5 6$php = getenv('TEST_PHP_EXECUTABLE'); 7$ds = [ 8 0 => ['pipe', 'r'], 9 1 => ['pipe', 'w'], 10 2 => ['pipe', 'w'], 11]; 12 13echo "Empty command array:"; 14var_dump(proc_open([], $ds, $pipes)); 15 16echo "\nNul byte in program name:"; 17var_dump(proc_open(["php\0oops"], $ds, $pipes)); 18 19echo "\nNul byte in argument:"; 20var_dump(proc_open(["php", "arg\0oops"], $ds, $pipes)); 21 22echo "\nBasic usage:\n"; 23$proc = proc_open([$php, '-r', 'echo "Hello World!\n";'], $ds, $pipes); 24fpassthru($pipes[1]); 25proc_close($proc); 26 27putenv('ENV_1=ENV_1'); 28$env = ['ENV_2' => 'ENV_2']; 29$cmd = [$php, '-n', '-r', 'var_dump(getenv("ENV_1"), getenv("ENV_2"));']; 30 31echo "\nEnvironment inheritance:\n"; 32$proc = proc_open($cmd, $ds, $pipes); 33fpassthru($pipes[1]); 34proc_close($proc); 35 36echo "\nExplicit environment:\n"; 37$proc = proc_open($cmd, $ds, $pipes, null, $env); 38fpassthru($pipes[1]); 39proc_close($proc); 40 41echo "\nCheck that arguments are correctly passed through:\n"; 42$args = [ 43 "Simple", 44 "White space\ttab\nnewline", 45 '"Quoted"', 46 'Qu"ot"ed', 47 '\\Back\\slash\\', 48 '\\\\Back\\\\slash\\\\', 49 '\\"Qu\\"ot\\"ed\\"', 50]; 51$cmd = [$php, '-r', 'var_export(array_slice($argv, 1));', '--', ...$args]; 52$proc = proc_open($cmd, $ds, $pipes); 53fpassthru($pipes[1]); 54proc_close($proc); 55 56?> 57--EXPECTF-- 58Empty command array: 59Warning: proc_open(): Command array must have at least one element in %s on line %d 60bool(false) 61 62Nul byte in program name: 63Warning: proc_open(): Command array element 1 contains a null byte in %s on line %d 64bool(false) 65 66Nul byte in argument: 67Warning: proc_open(): Command array element 2 contains a null byte in %s on line %d 68bool(false) 69 70Basic usage: 71Hello World! 72 73Environment inheritance: 74string(5) "ENV_1" 75bool(false) 76 77Explicit environment: 78bool(false) 79string(5) "ENV_2" 80 81Check that arguments are correctly passed through: 82array ( 83 0 => 'Simple', 84 1 => 'White space tab 85newline', 86 2 => '"Quoted"', 87 3 => 'Qu"ot"ed', 88 4 => '\\Back\\slash\\', 89 5 => '\\\\Back\\\\slash\\\\', 90 6 => '\\"Qu\\"ot\\"ed\\"', 91) 92