1
0
mirror of https://github.com/php/php-src.git synced 2026-03-26 17:22:15 +01:00
Files
archived-php-src/ext/standard/tests/general_functions/proc_open_array.phpt
Tyson Andre 1e9a5c67ef Rename standard array function parameters to $array
This is targeting 8.0.

`$arg` seems like a poor choice of a name,
especially if the function were to have arguments added.

In many cases, the php.net documentation already has $array for these functions.
E.g. https://www.php.net/manual/en/function.array-intersect.php

I'd assume that since named arguments was added to 8.0 near the feature freeze,
PHP's maintainers had planned to make the names consistent
and gradually use the same name for  docs and implementation.
2020-08-11 19:11:59 -04:00

101 lines
2.1 KiB
PHP

--TEST--
Using proc_open() with a command array (no shell)
--FILE--
<?php
$php = getenv('TEST_PHP_EXECUTABLE');
$ds = [
0 => ['pipe', 'r'],
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
];
echo "Empty command array:\n";
try {
proc_open([], $ds, $pipes);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
echo "\nNul byte in program name:\n";
try {
proc_open(["php\0oops"], $ds, $pipes);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
echo "\nNul byte in argument:\n";
try {
proc_open(["php", "array\0oops"], $ds, $pipes);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
echo "\nBasic usage:\n";
$proc = proc_open([$php, '-r', 'echo "Hello World!\n";'], $ds, $pipes);
fpassthru($pipes[1]);
proc_close($proc);
putenv('ENV_1=ENV_1');
$env = ['ENV_2' => 'ENV_2'];
$cmd = [$php, '-n', '-r', 'var_dump(getenv("ENV_1"), getenv("ENV_2"));'];
echo "\nEnvironment inheritance:\n";
$proc = proc_open($cmd, $ds, $pipes);
fpassthru($pipes[1]);
proc_close($proc);
echo "\nExplicit environment:\n";
$proc = proc_open($cmd, $ds, $pipes, null, $env);
fpassthru($pipes[1]);
proc_close($proc);
echo "\nCheck that arguments are correctly passed through:\n";
$args = [
"Simple",
"White space\ttab\nnewline",
'"Quoted"',
'Qu"ot"ed',
'\\Back\\slash\\',
'\\\\Back\\\\slash\\\\',
'\\"Qu\\"ot\\"ed\\"',
];
$cmd = [$php, '-r', 'var_export(array_slice($argv, 1));', '--', ...$args];
$proc = proc_open($cmd, $ds, $pipes);
fpassthru($pipes[1]);
proc_close($proc);
?>
--EXPECT--
Empty command array:
proc_open(): Argument #1 ($cmd) must have at least one element
Nul byte in program name:
Command array element 1 contains a null byte
Nul byte in argument:
Command array element 2 contains a null byte
Basic usage:
Hello World!
Environment inheritance:
string(5) "ENV_1"
bool(false)
Explicit environment:
bool(false)
string(5) "ENV_2"
Check that arguments are correctly passed through:
array (
0 => 'Simple',
1 => 'White space tab
newline',
2 => '"Quoted"',
3 => 'Qu"ot"ed',
4 => '\\Back\\slash\\',
5 => '\\\\Back\\\\slash\\\\',
6 => '\\"Qu\\"ot\\"ed\\"',
)