|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2003-05-28 10:45 UTC] csnyder at chxo dot com
 The current behavior of getopts() is counter-intuitive.
From the manual:
"If an option does not have an argument, the value will be set to FALSE."
But this leads to a script like the following:
#!/usr/local/bin/php
<?
$options = getopt("abcdef");
if ($options['e']===FALSE) print "I took e!";
?>
This is confusing -- we test for the presence of an option in the command line by checking whether it is FALSE?
It would be quite helpful, at least in cases where no additional value was expected (an option string of "a" vs. an option string of "a:") for getopts to set the value to TRUE. The script above could then be:
#!/usr/local/bin/php
<?
$options = getopt("abcdef");
if ($options['e']) print "I took e!";
?>
...which is much easier to figure out.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 14:00:01 2025 UTC | 
Changing this would break backwards compatibility. And btw. this is much more intuitive: #!/usr/local/bin/php <?php $options = getopt("abcdef"); if (isset($options['e'])) print "I took e!"; ?>