Bug #69015 [Opn]: php-cgi's getopt does not see $argv

From: Date: Thu, 12 Feb 2015 13:24:44 +0000
Subject: Bug #69015 [Opn]: php-cgi's getopt does not see $argv
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190628@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69015&edit=1 ID: 69015 Updated by: fa@php.net Reported by: lonnie at abelbeck dot com Summary: php-cgi's getopt does not see $argv Status: Open Type: Bug Package: CGI/CLI related Operating System: Linux PHP Version: 5.5.21 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2015-02-12 07:28:25] laruence@php.net 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? thanks ------------------------------------------------------------------------ [2015-02-08 16:05:39] lonnie at abelbeck dot com 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 this bug report at https://bugs.php.net/bug.php?id=69015&edit=1

« previous php.bugs (#190628) next »