« PharFileInfo::compress
PharFileInfo::decompress »

PharFileInfo::__construct

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

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

説明

public function 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

関連キーワード:
phar   PharFileInfo   行番号   Phar   construct   エントリ   line   text   testfile   filename   path   foreach   there   dude   compress   decompress   直接   offsetGet   BadMethodCallException   オープン   UnexpectedValueException   nthere   ndude   catch   Exception
関連する関数・ページ:
pharfileinfo.destruct   pharfileinfo.getpharflags   pharfileinfo.decompress   pharfileinfo.compress   pharfileinfo.setmetadata   pharfileinfo.getcompressedsize