CakeFest 2024: The Official CakePHP Conference

PharFileInfo::__construct

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL phar >= 1.0.0)

PharFileInfo::__constructPhar エントリオブジェクトを作成する

説明

public PharFileInfo::__construct(string $filename)

これは直接コールしてはいけません。PharFileInfo オブジェクトを作成するには、 配列へのアクセスを通じて Phar::offsetGet() をコールします。

パラメータ

filename

ファイルを取得するための完全な url。 ファイル my/file.php の情報を phar boo.phar から取得したい場合は、 このエントリは phar://boo.phar/my/file.php となります。

エラー / 例外

__construct() が二度コールされた場合に BadMethodCallException、 phar の URL がおかしかったり phar がオープンできなかったり、 あるいはファイルが phar 内で見つからなかった場合に UnexpectedValueException がスローされます。

例1 PharFileInfo::__construct() の例

<?php
try {
$p = new Phar('/path/to/my.phar', 0, 'my.phar');
$p['testfile.txt'] = "hi\nthere\ndude";
$file = $p['testfile.txt'];
foreach (
$file as $line => $text) {
echo
"行番号 $line: $text";
}
// これも動作します
$file = new PharFileInfo('phar:///path/to/my.phar/testfile.txt');
foreach (
$file as $line => $text) {
echo
"行番号 $line: $text";
}
} catch (
Exception $e) {
echo
'Phar 操作に失敗しました: ', $e;
}
?>

上の例の出力は以下となります。

行番号 1: hi
行番号 2: there
行番号 3: dude
行番号 1: hi
行番号 2: there
行番号 3: dude

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top