php.net |  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
Votes:6
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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
7 + 18 = ?
Subscribe to this entry?

 
 [2006-01-19 18:05 UTC] oli at isnic dot is
Description:
------------
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) {
      print($key."=".$value."\n");
    }
    else {
      print($key."=false\n");
    }
  }
}
exit(0);


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


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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

test.php:

#!sapi/cli/php
<?php
$options = getopt("b:s");
var_dump($options);
?>

#./t.php -s -b 1
array(2) {
  ["s"]=>
  bool(false)
  ["b"]=>
  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 
#!/usr/local/bin/php
<?php
$options = getopt("b:s");
var_dump($options);
?>
# ./t.php -s -b 1
array(0) {
}
 [2006-01-20 11:31 UTC] sniper@php.net
Ilia, this is propably some issue on FreeBSD, I can't reproduce with Linux.
 [2006-01-20 13:30 UTC] tony2001@php.net
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] tony2001@php.net
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] tony2001@php.net
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] sniper@php.net
Deleted irrelevant comments..Tony, can you just commit that patch of yours and ignore the whining? :)
 [2006-02-12 11:02 UTC] tony2001@php.net
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] bfrance@php.net
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
http://snaps.php.net/.
 
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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 22:01:28 2024 UTC