zval *arg_zv;
uint32_t num_elems = zend_hash_num_elements(Z_ARRVAL_P(command_zv));
if (num_elems == 0) {
- php_error_docref(NULL, E_WARNING, "Command array must have at least one element");
- RETURN_FALSE;
+ zend_value_error("Command array must have at least one element");
+ return;
}
#ifdef PHP_WIN32
zval *ztype;
if (str_index) {
- php_error_docref(NULL, E_WARNING, "descriptor spec must be an integer indexed array");
+ zend_value_error("Descriptor spec must be an integer indexed array");
goto exit_fail;
}
descriptors[ndesc].mode = DESC_FILE;
} else if (Z_TYPE_P(descitem) != IS_ARRAY) {
- php_error_docref(NULL, E_WARNING, "Descriptor item must be either an array or a File-Handle");
+ zend_value_error("Descriptor item must be either an array or a File-Handle");
goto exit_fail;
} else {
goto exit_fail;
}
} else {
- php_error_docref(NULL, E_WARNING, "Missing handle qualifier in array");
+ zend_value_error("Missing handle qualifier in array");
goto exit_fail;
}
goto exit_fail;
}
} else {
- php_error_docref(NULL, E_WARNING, "Missing mode parameter for 'pipe'");
+ zend_value_error("Missing mode parameter for 'pipe'");
goto exit_fail;
}
goto exit_fail;
}
} else {
- php_error_docref(NULL, E_WARNING, "Missing file name parameter for 'file'");
+ zend_value_error("Missing file name parameter for 'file'");
goto exit_fail;
}
goto exit_fail;
}
} else {
- php_error_docref(NULL, E_WARNING, "Missing mode parameter for 'file'");
+ zend_value_error("Missing mode parameter for 'file'");
goto exit_fail;
}
php_file_descriptor_t childend;
if (!ztarget) {
- php_error_docref(NULL, E_WARNING, "Missing redirection target");
+ zend_value_error("Missing redirection target");
goto exit_fail;
}
if (Z_TYPE_P(ztarget) != IS_LONG) {
- php_error_docref(NULL, E_WARNING, "Redirection target must be an integer");
+ zend_value_error("Redirection target must be an integer");
goto exit_fail;
}
2 => ['pipe', 'w'],
];
-echo "Empty command array:";
-var_dump(proc_open([], $ds, $pipes));
+echo "Empty command array:\n";
+try {
+ proc_open([], $ds, $pipes);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
echo "\nNul byte in program name:";
var_dump(proc_open(["php\0oops"], $ds, $pipes));
?>
--EXPECTF--
Empty command array:
-Warning: proc_open(): Command array must have at least one element in %s on line %d
-bool(false)
+Command array must have at least one element
Nul byte in program name:
Warning: proc_open(): Command array element 1 contains a null byte in %s on line %d
proc_open("$php -n $callee", $spec, $pipes);
$spec[$i] = 1;
-proc_open("$php -n $callee", $spec, $pipes);
+try {
+ proc_open("$php -n $callee", $spec, $pipes);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
$spec[$i] = array('pipe', "test");
proc_open("$php -n $callee", $spec, $pipes);
?>
--EXPECTF--
Warning: proc_open(): pi is not a valid descriptor spec/mode in %s on line %d
-
-Warning: proc_open(): Descriptor item must be either an array or a File-Handle in %s on line %d
+Descriptor item must be either an array or a File-Handle
array(4) {
[3]=>
resource(%d) of type (Unknown)
<?php
$php = getenv('TEST_PHP_EXECUTABLE');
-var_dump(proc_open([$php], [['redirect']], $pipes));
-var_dump(proc_open([$php], [['redirect', 'foo']], $pipes));
-var_dump(proc_open([$php], [['redirect', 42]], $pipes));
+try {
+ proc_open([$php], [['redirect']], $pipes);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
+
+try {
+ proc_open([$php], [['redirect', 'foo']], $pipes);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
+
+try {
+ proc_open([$php], [['redirect', 42]], $pipes);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
echo "\nWith pipe:\n";
$cmd = [$php, '-r', 'echo "Test\n"; fprintf(STDERR, "Error");'];
?>
--EXPECTF--
-Warning: proc_open(): Missing redirection target in %s on line %d
-bool(false)
-
-Warning: proc_open(): Redirection target must be an integer in %s on line %d
-bool(false)
+Missing redirection target
+Redirection target must be an integer
-Warning: proc_open(): Redirection target 42 not found in %s on line %d
-bool(false)
+Warning: proc_open(): Redirection target 42 not found in %s
With pipe:
array(1) {