php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #23859 getopts() indicates set options using FALSE
Submitted: 2003-05-28 10:45 UTC Modified: 2003-05-28 20:45 UTC
From: csnyder at chxo dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4.3.1 OS: Linux / FreeBSD
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-28 20:45 UTC] sniper@php.net
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!";
?>



 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 20:01:32 2024 UTC