getopt
Function • Params and return types changed in PHP 8.0
Gets options from the command line argument list.
getopt Function synopsis
getopt(
string $short_options,
array $long_options = [],
&$rest_index = null
): array|false
Parameters
$short_options
Typestring
$long_options
OptionalTypearrayDefault value[]
$rest_index
Passed by reference, OptionalDefault valuenull
Note that the parameter
$rest_indexis passed by reference, and contains additional/updated context data that may be useful.
Return value
Typearray|false
This function will return an array of option / argument pairs, or false on failure.
The parsing of options will end at the first non-option found, anything
that follows is discarded. Changes to the getopt Function
PHP 8.0
- Return type added:
array|false - Parameter name of parameter #1 changed:
$optionsto$short_options - Parameter type added for parameter #1 (
$short_options):string - Parameter name of parameter #2 changed:
$optsto$long_options - Parameter type added for parameter #2 (
$long_options):array - Parameter default value added for position #2 (
$long_options):[] - Parameter name of parameter #3 changed:
$optindto$rest_index - Parameter default value added for position #3 (
$rest_index):null
getopt(
- $options,
+ string $short_options,
- $opts,
+ array $long_options = [],
- &$optind
+ &$rest_index = null
- )
+ ): array|false PHP 7.1
- Optional parameter added - #3:
&$optind
-getopt($options, $opts)
+getopt(
+ $options,
+ $opts,
+ &$optind
+ ) getopt Function Availability
getopt Function Availability| PHP Version | Availability |
|---|---|
| PHP 8.6Upcoming Release | Yes |
| PHP 8.5Supported (Latest) | Yes |
| PHP 8.4Supported | Yes |
| PHP 8.3Security-Fixes Only | Yes |
| PHP 8.2Security-Fixes Only | Yes |
| PHP 8.1Unsupported | Yes |
| PHP 8.0Unsupported | Yes |
| PHP 7.4Unsupported | Yes |
| PHP 7.3Unsupported | Yes |
| PHP 7.2Unsupported | Yes |
| PHP 7.1Unsupported | Yes |
| PHP 7.0Unsupported | Yes |
| PHP 5.6Unsupported | Yes |
| PHP 5.5Unsupported | Yes |
| PHP 5.4Unsupported | Yes |
| PHP 5.3Unsupported | Yes |