|  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
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
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
If you don't provide required arguments, getopt doesn't return FALSE;

# php example.php

array(0) {

Test script:
$shortopts = "f:";  // Required value

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

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



Expected result:

Actual result:
array(0) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-11 16:27 UTC]
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Package: Unknown/Other Function +Package: PHP options/info functions
 [2018-05-11 16:27 UTC]
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] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 08:01:29 2024 UTC