(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL phar >= 1.0.0)
PharFileInfo::__construct — 建構 Phar 項目物件
不應該直接呼叫這個函式。PharFileInfo 物件的初始化是透過陣列存取呼叫 Phar::offsetGet() 來完成的。
檔名
用於擷取檔案的完整 URL。如果您希望從 Phar 封存 `boo.phar` 中擷取檔案 `my/file.php` 的資訊,則項目應為 `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 number $line: $text";
}
// 這也適用
$file = new PharFileInfo('phar:///path/to/my.phar/testfile.txt');
foreach ($file as $line => $text) {
echo "line number $line: $text";
}
} catch (Exception $e) {
echo 'Phar 操作失敗: ', $e;
}
?>
以上範例將輸出
line number 1: hi line number 2: there line number 3: dude line number 1: hi line number 2: there line number 3: dude