php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65931 getopt fails to return optional argument when specified
Submitted: 2013-10-18 22:05 UTC Modified: 2013-10-25 06:02 UTC
From: support at shockandawemedia dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: Irrelevant OS: Gnu Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: support at shockandawemedia dot com
New email:
PHP Version: OS:

 

 [2013-10-18 22:05 UTC] support at shockandawemedia dot com
Description:
------------
---
From manual page: http://www.php.net/function.getopt#refsect1-function.getopt-returnvalues
---


This function is useless if it cannot work with optional arguments at all.



Test script:
---------------
<?php

$argsA = getopt("a:b::c:");
var_dump($argsA);

?>

Expected result:
----------------
The string value 'arg2' should have appeared in the argument array for index 'b'.  

Actual result:
--------------
$ php ./gotest.php -a arg1 -b arg2 -c arg3
array(3) {
  ["a"]=>
  string(4) "arg1"
  ["b"]=>
  bool(false)
  ["c"]=>
  string(4) "arg3"
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-25 05:59 UTC] yohgaki@php.net
-Status: Open +Status: Not a bug
 [2013-10-25 05:59 UTC] yohgaki@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

I think we don't support following form

$ php ./gotest.php -a arg1 -b arg2 -c arg3

but

$ php ./gotest.php -a arg1 -b=arg2 -c arg3

or 

$ php ./gotest.php -a arg1 -barg2 -c arg3
 [2013-10-25 06:02 UTC] yohgaki@php.net
If this is feature request, duplicate of #26818
 [2013-11-15 16:30 UTC] support at shockandawemedia dot com
Hi,

I reported it as a bug, because, at least as I understood the php manual on the function, it should have operated as I expected-- but didn't.  All elements in the array should be filled in.

Nonetheless, close this.  I wrote a CLI handler in 40-lines that offers full fexibility.  Don't you just love PCRE!

Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 02:01:29 2024 UTC