|  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
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
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.
Bug Type:
From: rik dot davis at logiqnet dot net
New email:
PHP Version: OS:


 [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-2021 The PHP Group
All rights reserved.
Last updated: Thu Oct 28 11:03:33 2021 UTC