php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60997 getopt() parses optional values incorrectly
Submitted: 2012-02-06 23:51 UTC Modified: 2012-03-08 19:47 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: eric at wepay dot com Assigned:
Status: Not a bug Package: CGI/CLI related
PHP Version: 5.3.10 OS: Linux CentOS
Private report: No CVE-ID: None
 [2012-02-06 23:51 UTC] eric at wepay dot com
Description:
------------
If a CLI argument is passed with leading whitespace, the value is not picked up by 
getopt() if specified as an optional value (with two colons). This is contrary to 
the documentation, which states, "Option values are the first argument after the 
string. It does not matter if a value has leading white space or not."

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

var_dump(getopt('v'));
var_dump(getopt('v:'));
var_dump(getopt('v::'));


?>


$ ./test.php -v2 asdf   # behaves as expected
$ ./test.php -v=2 asdf  # behaves as expected
$ ./test.php -v 2 asdf  # problem case, shown in actual result


Expected result:
----------------
array(1) {
  ["v"]=>
  bool(false)
}
array(1) {
  ["v"]=>
  string(1) "2"
}
array(1) {
  ["v"]=>
  string(1) "2"
}


Actual result:
--------------
array(1) {
  ["v"]=>
  bool(false)
}
array(1) {
  ["v"]=>
  string(1) "2"
}
array(1) {
  ["v"]=>
  bool(false)
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-07 03:45 UTC] carloschilazo at gmail dot com
Documentation also states: 

Note: Optional values do not accept " " (space) as a separator.
 [2012-03-08 19:47 UTC] iliaa@php.net
-Status: Open +Status: Not a bug
 [2012-03-08 19:47 UTC] iliaa@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


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 21:01:29 2024 UTC