rfc:shell_exec_result_code_param

PHP RFC: Add an optional parameter $result_code to shell_exec()

Introduction

The shell_exec() function is used to execute an external program and grab its entire output as a string, but it lacks a way to capture the exit code of the launched program contrarily to all the other functions of the same family (exec, system, passthru).

Proposal

This RFC proposes the addition of a second, optional parameter $result_code to the shell_exec() function:

 function shell_exec(string $command, &$result_code = null): string|false|null {} 

If $result_code is present, the function will put the return code of the program into it. The same parameter and behaviour is found in exec(), system() and passthru() functions.

Backward Incompatible Changes

No backward compatibility breaks.

Proposed PHP Version(s)

Next PHP 8.x, currently PHP 8.2.

RFC Impact

To SAPIs

None.

To Existing Extensions

None.

To Opcache

None.

New Constants

No new constants introduced.

php.ini Defaults

No new php.ini options introduced.

Unaffected PHP Functionality

  • Behaviour of shell_exec() when called with one parameter will not change;
  • Backtick operator functionality is unaffected.

Proposed Voting Choices

Yes/No vote, super majority of 2/3 required to pass.

Implementation

References

rfc/shell_exec_result_code_param.txt · Last modified: 2021/11/27 05:03 by lpt