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
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2018 The PHP Group
All rights reserved.
Last updated: Wed Dec 12 23:01:26 2018 UTC