php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76325 getopt doesn't return false when required argument isn't provided
Submitted: 2018-05-11 06:48 UTC Modified: 2018-05-11 16:27 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: rvalihanov at a-r-b dot ru Assigned:
Status: Verified Package: PHP options/info functions
PHP Version: 7.0.30 OS: Debian 8
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: rvalihanov at a-r-b dot ru
New email:
PHP Version: OS:

 

 [2018-05-11 06:48 UTC] rvalihanov at a-r-b dot ru
Description:
------------
If you don't provide required arguments, getopt doesn't return FALSE;


# php example.php

array(0) {
}




Test script:
---------------
<?php
$shortopts = "f:";  // Required value

$longopts  = array(
    "required:",     // Required value
);

$options = getopt($shortopts, $longopts);

var_dump($options);

?>


Expected result:
----------------
bool(false)

Actual result:
--------------
array(0) {
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-11 16:27 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Package: Unknown/Other Function +Package: PHP options/info functions
 [2018-05-11 16:27 UTC] cmb@php.net
This is expected behavior (see also the first example[1]).
getopt() does not fail if an option is missing; instead the option
is not included in the return value.  The function only fails
(i.e. it returns FALSE), if $argv is missing (e.g. when PHP is
running as Apache module).

I think the documentation could be improved here.

[1] <http://de2.php.net/manual/en/function.getopt.php#refsect1-function.getopt-examples>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 08 18:01:27 2024 UTC