php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65925 Incorrect return value for shell_exec(), backticks
Submitted: 2013-10-18 00:36 UTC Modified: 2013-10-22 12:05 UTC
From: krewecherl at gmail dot com Assigned: daverandom (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: krewecherl at gmail dot com
New email:
PHP Version: OS:

 

 [2013-10-18 00:36 UTC] krewecherl at gmail dot com
Description:
------------
The page at http://www.php.net/manual/en/function.shell-exec.php reads:

  Return Values
  The output from the executed command or NULL if an error occurred.

This is incorrect, as some of the commenters have noted. Successfully executed commands (exit status 0) that produce no output also return NULL. The return value is documented to be a string, so we would expect an empty string in the case of no output.

I would even argue that this is a bug, because it prevents detecting a non-zero exit status, but changing the behavior at this late stage would probably do more damage than good.

In any case, it needs to be properly documented.

Test script:
---------------
$ php -r 'system("sync", $status); var_dump($status);'
int(0)

$ php -r '$rv = shell_exec("sync"); var_dump($rv);'
NULL

$ php -r '$rv = `sync`; var_dump($rv);'
NULL


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-22 12:04 UTC] daverandom@php.net
Automatic comment from SVN on behalf of daverandom
Revision: http://svn.php.net/viewvc/?view=revision&revision=331914
Log: Note that shell_exec() also returns NULL when the executed command produces no output. Fixes bug #65925.
 [2013-10-22 12:05 UTC] daverandom@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: daverandom
 [2013-10-22 12:05 UTC] daverandom@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 04:00:01 2026 UTC