php8.5
Home/ Manual/ spl / splfileinfo/ SplFileInfo::getPathInfo

SplFileInfo::getPathInfo

PHP function Edit on GitHub ✎

(PHP 5 >= 5.1.2, PHP 7, PHP 8)

Gets an SplFileInfo object for the path

Description

SplFileInfo::getPathInfo(string|null $class = null): SplFileInfo|null

Gets an SplFileInfo object for the parent of the current file.

Parameters

class

Name of an SplFileInfo derived class to use, or itself if null.

Return Values

Returns an SplFileInfo object for the parent path of the file on success, or null on failure.

Changelog

VersionDescription
8.0.0class is now nullable.

Examples

SplFileInfo::getPathInfo() example

php
<?php
$info = new SplFileInfo('/usr/bin/php');
$parent_info = $info->getPathInfo();
var_dump($parent_info->getRealPath());
?>

The above example will output something similar to:

output
string(8) "/usr/bin"

See Also

  • SplFileInfo::setInfoClass

Source: reference/spl/splfileinfo/getpathinfo.xml · from the official PHP manual (php/doc-en)