|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36091 getopt() returns false on every call
Submitted: 2006-01-19 18:05 UTC Modified: 2006-02-23 04:56 UTC
Avg. Score:4.3 ± 0.7
Reproduced:5 of 6 (83.3%)
Same Version:4 (80.0%)
Same OS:4 (80.0%)
From: oli at isnic dot is Assigned:
Status: Closed Package: CGI/CLI related
PHP Version: 5.1.2, 4.4.2 OS: FreeBSD 5.4
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: oli at isnic dot is
New email:
PHP Version: OS:


 [2006-01-19 18:05 UTC] oli at isnic dot is
The "fix" in bug #35594 breaks getopt() in PHP4 completely
on my system, it returns false on every call now.
FreeBSD 5.4-RELEASE-p8 and php-4.4.2 updated today.
Removing the "fix" makes getopt() work again.

Reproduce code:
$options = getopt("b:s");

if (!$options) {
  print("\$options is false\n");
else {
  foreach ($options as $key => $value) {
    if ($value) {
    else {

Expected result:
#./getopt.php -s -b 1

Actual result:
#./getopt.php -s -b 1
$options is false


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-19 20:46 UTC]
This works just fine for me:


$options = getopt("b:s");

#./t.php -s -b 1
array(2) {
  string(1) "1"

Works the same with both 5.1.2 and 4.4.2.
Try this same script please. (change the hashbang path, of course :)
 [2006-01-20 10:39 UTC] oli at isnic dot is
Same result, I also tried with -n so that nothing was being 
taken from the php.ini, and again it works fine when 
compiled without the forementioned "fix"

# cat t.php 
$options = getopt("b:s");
# ./t.php -s -b 1
array(0) {
 [2006-01-20 11:31 UTC]
Ilia, this is propably some issue on FreeBSD, I can't reproduce with Linux.
 [2006-01-20 13:30 UTC]
Changing optind re-initalization to optind = 1; fixes it for me on FreeBSD (and works on Linux).
Though it still makes we wonder why FreeBSD prefers to have its own implementation of everything: for some reasons they also have `extern int optreset;`, but it doesn't make any difference whether you change it or not.
 [2006-01-24 01:15 UTC]
Reassigned to myself.
I'll commit the patch as soon as I figure out if it works on Solaris and AIX.
 [2006-01-30 10:56 UTC] oli at isnic dot is
I don't see any reference to optreset in the php4 code I have 
so I assume that you are testing something locally, are you 
trying to set optreset to 0 or 1, since 1 should be the 
correct value.
 [2006-01-30 11:04 UTC]
Changing both optind & optreset to 1 does the same as changing only optind to 1. I.e. multiple calls to getopt() return expected result after this change.

This code apparently doesn't exist in any branches, because I had no chance to test it on Solaris and AIX yet.
 [2006-01-30 12:13 UTC] oli at isnic dot is
optreset works for me on FreeBSD just as optind does when set 
to 1 and not 0 as it is done now in php.
 [2006-02-12 09:28 UTC]
Deleted irrelevant comments..Tony, can you just commit that patch of yours and ignore the whining? :)
 [2006-02-12 11:02 UTC]
It's oneliner - commit it yourself if you care about BSD, I'm not going to touch it again.
 [2006-02-23 04:56 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Closing this bug as I have commited the change into cvs for all branches.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Aug 04 05:01:24 2021 UTC