Doc #74827 [Com]: Documentation incorrect regarding getopt options

From: Date: Wed, 03 Jul 2019 16:41:27 +0000
Subject: Doc #74827 [Com]: Documentation incorrect regarding getopt options
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16794@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74827&edit=1 ID: 74827 Comment by: ron at roncemer dot com Reported by: sciron64 at sindtech dot org Summary: Documentation incorrect regarding getopt options Status: Not a bug Type: Documentation Problem Package: PHP options/info functions Operating System: GNU/Linux PHP Version: 7.0.20 Block user comment: N Private report: N New Comment: Sorry, but this most definitely IS a bug. The optind documentation says: optind If the optind parameter is present, then the index where argument parsing stopped will be written to this variable. It should also mention, RIGHT THERE, that the optind argument was introduced in PHP 7.1.0. By not doing that, the documentation is misleading people to write code which may test out fine on PHP 7.1.0 or newer, but generates errors in slightly older versions of PHP. It's not unusual for people to develop on Ubuntu 18.04 LTS desktop, and deploy to Ubuntu 16.04 LTS server, which is the exact scenario which triggers this issue. Update the documentation to make it ABUNDANTLY CLEAR that this third argument is not available in PHP versions earlier than 7.1.0. Previous Comments: ------------------------------------------------------------------------ [2017-06-29 03:15:38] requinix@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php http://php.net/manual/en/function.getopt.php#refsect1-function.getopt-changelog ------------------------------------------------------------------------ [2017-06-29 02:40:46] sciron64 at sindtech dot org Description: ------------ --- From manual page: http://www.php.net/function.getopt --- http://php.net/manual/en/function.getopt.php states 3 options can be passed to getopt: "array getopt ( string $options [, array $longopts [, int &$optind ]] )" Except $optind is unable to be processed by PHP v7.0.20. To put another way, getopt only accepts _TWO_ parameters, not the documented three. Test script: --------------- <?php $optInd = -1; getopt("abcd",array("alfa", "beta", "charlie", "delta"), $optInd); Expected result: ---------------- No error message when using 3rd parameter. Actual result: -------------- PHP Warning: getopt() expects at most 2 parameters, 3 given in /var/www/scripts/getopt-test.php on line 3 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74827&edit=1

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