pathinfo
Function • Params and return types changed in PHP 8.0
Returns information about a file path.
pathinfo Function synopsis
pathinfo(string $path, int $flags = PATHINFO_ALL): array|string
Parameters
$path
Typestring
The path to be parsed.
$flags
OptionalTypeintDefault valuePATHINFO_ALL
If present, specifies a specific element to be returned; one of
PATHINFO_DIRNAME,
PATHINFO_BASENAME,
PATHINFO_EXTENSION or
PATHINFO_FILENAME.
Return value
Typearray|string
If the $flags parameter is not passed, an
associative array containing the following elements is
returned:
dirname, basename,
extension (if any), and filename.
If the [`$path`](#param-path) has more than one extension,
[`PATHINFO_EXTENSION`](/codex/PATHINFO_EXTENSION) returns only the last one and
[`PATHINFO_FILENAME`](/codex/PATHINFO_FILENAME) only strips the last one.
(see first example below).
If the [`$path`](#param-path) does not have an extension, no
`extension` element will be returned
(see second example below).
If the `basename` of the [`$path`](#param-path) starts
with a dot, the following characters are interpreted as
`extension`, and the `filename` is empty
(see third example below).
If $flags is present, returns a
string containing the requested element.
Changes to the pathinfo Function
PHP 8.0
- Return type added:
array|string - Parameter type added for parameter #1 (
$path):string - Parameter name of parameter #2 changed:
$optionsto$flags - Parameter type added for parameter #2 (
$flags):int - Parameter default value added for position #2 (
$flags):PATHINFO_ALL
- pathinfo($path, $options)
+ pathinfo(string $path, int $flags = PATHINFO_ALL): array|string pathinfo Function Availability
pathinfo 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 |