Req #73481 [Com]: getopt function argument handling
| From: | php at duncanc dot co dot uk | Date: | Sun, 20 Nov 2016 21:57:56 +0000 |
| Subject: | Req #73481 [Com]: getopt function argument handling | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-205494@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73481&edit=1
ID: 73481
Comment by: php at duncanc dot co dot uk
Reported by: rik dot davis at logiqnet dot net
Summary: getopt function argument handling
Status: Open
Type: Feature/Change Request
Package: Unknown/Other Function
Operating System: Centos 7.2.1511
PHP Version: 5.6.27
Block user comment: N
Private report: N
New Comment:
For breaking example 1 there's a note in the source that states:
"Optional value is not supported with -<arg> <val> style"
https://github.com/php/php-src/blob/45f7b2bcc8f95e793c1a9bb60da0848860c060fb/main/getopt.c#L167
For breaking example 2, I think any positional arguments must follow any named arguments, so
you'd need to do:
php test.php -ffilename.ext myarg
Previous Comments:
------------------------------------------------------------------------
[2016-11-08 18:05:16] rik dot davis at logiqnet dot net
Description:
------------
---
From manual page: http://www.php.net/function.getopt
---
Test script:
---------------
Save as test.php
<?php
$opts = getopt("f::");
print_r($opts);
?>
Working Example:
php test.php -ffilename.ext
Breaking Example 1:
php test.php -f filename.ext
Breaking Example 2:
php test.php myarg -f filename.ext
Expected result:
----------------
All examples should return the following;
Array
(
[f] => filename.ext
)
Actual result:
--------------
Working Example:
Array
(
[f] => filename.ext
)
Breaking Example 1:
> Does not allow for options to have space separated singular values.
Array
(
[f] =>
)
Breaking Example 2:
> Does not allow for options to exist after non-options arguments.
Array
(
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73481&edit=1