Edit report at https://bugs.php.net/bug.php?id=60997&edit=1

 ID:                 60997
 Comment by:         carloschilazo at gmail dot com
 Reported by:        eric at wepay dot com
 Summary:            getopt() parses optional values incorrectly
 Status:             Open
 Type:               Bug
 Package:            CGI/CLI related
 Operating System:   Linux CentOS
 PHP Version:        5.3.10
 Block user comment: N
 Private report:     N

 New Comment:

Documentation also states: 

Note: Optional values do not accept " " (space) as a separator.


Previous Comments:
------------------------------------------------------------------------
[2012-02-06 23:51:51] 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)
}



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60997&edit=1

Reply via email to