Skip to content

Commit 763deb4

Browse files
committed
Add $result_code parameter to shell_exec
1 parent ee3caef commit 763deb4

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

ext/standard/basic_functions.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ function escapeshellcmd(string $command): string {}
10051005
function escapeshellarg(string $arg): string {}
10061006

10071007
/** @refcount 1 */
1008-
function shell_exec(string $command): string|false|null {}
1008+
function shell_exec(string $command, int &$result_code = null): string|false|null {}
10091009

10101010
#ifdef HAVE_NICE
10111011
function proc_nice(int $priority): bool {}

ext/standard/basic_functions_arginfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,7 @@ ZEND_END_ARG_INFO()
11661166

11671167
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_shell_exec, 0, 1, MAY_BE_STRING|MAY_BE_FALSE|MAY_BE_NULL)
11681168
ZEND_ARG_TYPE_INFO(0, command, IS_STRING, 0)
1169+
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, result_code, "null")
11691170
ZEND_END_ARG_INFO()
11701171

11711172
#if defined(HAVE_NICE)

ext/standard/exec.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,15 @@ PHP_FUNCTION(shell_exec)
515515
FILE *in;
516516
char *command;
517517
size_t command_len;
518+
zval *ret_code = NULL;
518519
zend_string *ret;
519520
php_stream *stream;
521+
int ret_pclose;
520522

521-
ZEND_PARSE_PARAMETERS_START(1, 1)
523+
ZEND_PARSE_PARAMETERS_START(1, 2)
522524
Z_PARAM_STRING(command, command_len)
525+
Z_PARAM_OPTIONAL
526+
Z_PARAM_ZVAL(ret_code)
523527
ZEND_PARSE_PARAMETERS_END();
524528

525529
if (!command_len) {
@@ -542,8 +546,11 @@ PHP_FUNCTION(shell_exec)
542546

543547
stream = php_stream_fopen_from_pipe(in, "rb");
544548
ret = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0);
545-
php_stream_close(stream);
549+
ret_pclose = php_stream_close(stream);
546550

551+
if (ret_code) {
552+
ZEND_TRY_ASSIGN_REF_LONG(ret_code, ret_pclose);
553+
}
547554
if (ret && ZSTR_LEN(ret) > 0) {
548555
RETVAL_STR(ret);
549556
}

0 commit comments

Comments
 (0)