Bug->Doc #76325 [Opn->Ver]: getopt doesn't return false when required argument isn't provided

From: Date: Fri, 11 May 2018 16:27:33 +0000
Subject: Bug->Doc #76325 [Opn->Ver]: getopt doesn't return false when required argument isn't provided
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-15688@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76325&edit=1 ID: 76325 Updated by: cmb@php.net Reported by: rvalihanov at a-r-b dot ru Summary: getopt doesn't return false when required argument isn't provided -Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Package: Unknown/Other Function +Package: PHP options/info functions Operating System: Debian 8 PHP Version: 7.0.30 Block user comment: N Private report: N New Comment: 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> Previous Comments: ------------------------------------------------------------------------ [2018-05-11 06:48:53] 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) { } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76325&edit=1

« previous php.doc.bugs (#15688) next »