SplFileInfo::getPathInfo

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

SplFileInfo::getPathInfoパスの SplFileInfo オブジェクトを取得する

説明

public SplFileInfo::getPathInfo(?string $class = null): ?SplFileInfo

現在のファイルの親を表す SplFileInfo オブジェクトを取得します。

パラメータ

class

使用したい SplFileInfo 派生クラスの名前。 SplFileInfo 自体を使う場合は null を指定します。

戻り値

ファイルの親のパスの SplFileInfo オブジェクトを返します。 失敗時に null を返します。

変更履歴

バージョン 説明
8.0.0 class は、nullable になりました。

例1 SplFileInfo::getPathInfo() の例

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

上の例の出力は、 たとえば以下のようになります。

string(8) "/usr/bin"

参考

関連キーワード:  SplFileInfo, オブジェクト, パス, 取得, getPathInfo, string, クラス, バージョン, getFileInfo, setInfoClass