Bug #69015 [NEW]: php-cgi's getopt does not see $argv
| From: | lonnie at abelbeck dot com | Date: | Sun, 08 Feb 2015 16:05:40 +0000 |
| Subject: | Bug #69015 [NEW]: php-cgi's getopt does not see $argv | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-190534@lists.php.net to get a copy of this message | ||
From: lonnie at abelbeck dot com
Operating system: Linux
PHP version: 5.5.21
Package: CGI/CLI related
Bug Type: Bug
Bug description:php-cgi's getopt does not see $argv
Description:
------------
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
<?php
echo "PHP Version: ".phpversion()."\n";
echo "register_argc_argv=".ini_get('register_argc_argv')."\n";
var_dump($argv);
//var_dump($_SERVER['argv']);
$opts = getopt("abc:");
var_dump($opts);
?>
Expected result:
----------------
./test-argv-getopt.php -ab -c4
PHP Version: 5.5.21
register_argc_argv=1
array(3) {
[0]=>
string(22) "./test-argv-getopt.php"
[1]=>
string(3) "-ab"
[2]=>
string(3) "-c4"
}
array(3) {
["a"]=>
bool(false)
["b"]=>
bool(false)
["c"]=>
string(1) "4"
}
Actual result:
--------------
./test-argv-getopt.php -ab -c4
PHP Version: 5.5.21
register_argc_argv=1
array(3) {
[0]=>
string(22) "./test-argv-getopt.php"
[1]=>
string(3) "-ab"
[2]=>
string(3) "-c4"
}
bool(false)
--
Edit bug report at https://bugs.php.net/bug.php?id=69015&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69015&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69015&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69015&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69015&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69015&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69015&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69015&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69015&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69015&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69015&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69015&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69015&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69015&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69015&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69015&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69015&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69015&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69015&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69015&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69015&r=mysqlcfg