|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #73481 getopt function argument handling
Submitted: 2016-11-08 18:05 UTC Modified: 2018-02-28 22:13 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: rik dot davis at logiqnet dot net Assigned:
Status: Open Package: PHP options/info functions
PHP Version: 5.6.27 OS: Centos 7.2.1511
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-11-08 18:05 UTC] rik dot davis at logiqnet dot net
From manual page:

Test script:
Save as test.php
$opts = getopt("f::");


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;

  [f] => filename.ext

Actual result:
Working Example:
  [f] => filename.ext

Breaking Example 1:
> Does not allow for options to have space separated singular values.
  [f] =>

Breaking Example 2:
> Does not allow for options to exist after non-options arguments.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-20 21:57 UTC] php at duncanc dot co dot uk
For breaking example 1 there's a note in the source that states:
"Optional value is not supported with -<arg> <val> style"

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
 [2018-02-28 22:13 UTC]
-Package: Unknown/Other Function +Package: PHP options/info functions
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 13 06:01:27 2024 UTC