pathinfo

FunctionParams and return types changed in PHP 8.0

Returns information about a file path.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2-8.3
PHP 8.4
PHP 8.5
PHP 8.6

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: $options to $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

PHP VersionAvailability
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