#23859 [Opn->WFx]: getopts() indicates set options using FALSE

From: Date: Thu, 29 May 2003 01:45:13 +0000
Subject: #23859 [Opn->WFx]: getopts() indicates set options using FALSE
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-40624@lists.php.net to get a copy of this message
ID: 23859 Updated by: sniper@php.net Reported By: csnyder at chxo dot com -Status: Open +Status: Wont fix Bug Type: Feature/Change Request Operating System: Linux / FreeBSD PHP Version: 4.3.1 New Comment: 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!"; ?> Previous Comments: ------------------------------------------------------------------------ [2003-05-28 10:45:07] 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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=23859&edit=1

« previous php.bugs (#40624) next »