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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 23:01:29 2024 UTC