Doc #81352 [Opn]: Doc states getopt returns false when it really returns an empty array

From: Date: Thu, 12 Aug 2021 15:19:34 +0000
Subject: Doc #81352 [Opn]: Doc states getopt returns false when it really returns an empty array
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-19064@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81352&edit=1 ID: 81352 Updated by: cmb@php.net Reported by: edg at greenberg dot org Summary: Doc states getopt returns false when it really returns an empty array Status: Open Type: Documentation Problem -Package: Documentation problem +Package: PHP options/info functions Operating System: Centos 7 PHP Version: 7.4.22 Block user comment: N Private report: N New Comment: Prior to PHP 8.0.0, FALSE was returned if the function was called with unexpected parameters or parameter types. Most other functions returned NULL in that case. Anyhow, there is no need to document that, since this is actually undefined behavior[1]. For all relevant PHP versions, FALSE will also be returned, if neither $_SERVER nor $argv exists or are not arrays. [1] <https://www.php.net/manual/en/functions.internal.php> Previous Comments: ------------------------------------------------------------------------ [2021-08-12 12:26:49] edg at greenberg dot org Description: ------------ --- From manual page: https://php.net/function.getopt --- ON the manual page for getopt it states: > This function will return an array of option / argument pairs, or false on failure. When there are no options, it returns an empty array. So my bug report is to suggest that you indicate that "false on failure" refers to some other kind of failure and that no options found is indicated by an empty array. Thanks Test script: --------------- $options = getopt('', ['help', 'limit:', 'loops:', 'endtime:', 'tomorrow', 'agency:']); Expected result: ---------------- Based on the doc, if I call the script with no options, I expected failure. Actual result: -------------- I got an empty array. Note that I'm quite happy with the empty array, but wish that things in the doc had been a bit less ambiguous. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81352&edit=1

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