|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69015 php-cgi's getopt does not see $argv
Submitted: 2015-02-08 16:05 UTC Modified: 2015-02-14 14:36 UTC
From: lonnie at abelbeck dot com Assigned: laruence (profile)
Status: Closed Package: CGI/CLI related
PHP Version: 5.5.21 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: lonnie at abelbeck dot com
New email:
PHP Version: OS:


 [2015-02-08 16:05 UTC] lonnie at abelbeck dot com
On our embedded system, we only build the php-cgi version to save space, /usr/bin/php is php-cgi.

Note: This problem does not exist when calling php-cli via the command-line, only calling php-cgi via the command-line.

When upgrading from PHP 5.3 to PHP 5.5, there seems to be some optimization that keeps $argv from being seen by 'getopt' unless $_SERVER['argv'] is referenced in the script.  Interestingly $_SERVER['argv'] does not have to be executed to fix the behavior.

In the test script below, uncommenting "var_dump($_SERVER['argv']);" allows 'getopt' to work.

Test script:
#!/usr/bin/php -qnC
echo "PHP Version: ".phpversion()."\n";
echo "register_argc_argv=".ini_get('register_argc_argv')."\n";

$opts = getopt("abc:");

Expected result:
./test-argv-getopt.php -ab -c4
PHP Version: 5.5.21
array(3) {
  string(22) "./test-argv-getopt.php"
  string(3) "-ab"
  string(3) "-c4"
array(3) {
  string(1) "4"

Actual result:
./test-argv-getopt.php -ab -c4
PHP Version: 5.5.21
array(3) {
  string(22) "./test-argv-getopt.php"
  string(3) "-ab"
  string(3) "-c4"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-02-12 07:28 UTC]
this fix is easy.

but I'd like to discuss , php-cgi is face to fastcgi protocol, in such case, I don't think get opt make sense, right?

 [2015-02-12 13:24 UTC]
While it does not make sense usually I don't see a reason to have the SAPIs differ in behavior for no good reasons.
Unless there's some performance implications, I think it should be fixed.
 [2015-02-14 14:36 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: laruence
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Nov 29 23:01:27 2023 UTC