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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: csnyder at chxo dot com
New email:
PHP Version: OS:

 

 [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 Jun 17 19:01:30 2024 UTC