|  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
15 + 5 = ?
Subscribe to this entry?

 [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: Sun Oct 17 07:03:33 2021 UTC