php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #74827 Documentation incorrect regarding getopt options
Submitted: 2017-06-29 02:40 UTC Modified: 2019-07-03 18:11 UTC
From: sciron64 at sindtech dot org Assigned:
Status: Not a bug Package: PHP options/info functions
PHP Version: 7.0.20 OS: GNU/Linux
Private report: No CVE-ID: None
 [2017-06-29 02:40 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-29 03:15 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: Documentation problem +Package: PHP options/info functions
 [2017-06-29 03:15 UTC] 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
 [2019-07-03 16:41 UTC] ron at roncemer dot com
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.
 [2019-07-03 18:11 UTC] salathe@php.net
> Sorry, but this most definitely IS a bug.

The details of when changes happen to functions should be noted in the "Changelog" section of the relevant page. That is the correct place for those details. The changelog entry for the introduction of the $optind argument is already present in this section, as noted above. 

> Update the documentation to make it ABUNDANTLY CLEAR that this third argument is not available in PHP versions earlier than 7.1.0.

Again, the changelog section is what these sorts of details is for.

Thank you for your time and enthusiasm, however this is not a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC