W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL phar >= 1.0.0)
PharFileInfo::__construct — 構(gòu)造一個 Phar 入口對象
public PharFileInfo::__construct(string $filename)
這不應(yīng)該直接調(diào)用。而是 PharFileInfo 對象 通過數(shù)組訪問調(diào)用 Phar::offsetGet() 進(jìn)行初始化。
filename
用于檢索文件的完整 URL。如果您希望檢索信息 對于來自 phar 的文件, 條目應(yīng)為 。my/file.php
boo.phar
phar://boo.phar/my/file.php
如果 __construct() 被調(diào)用兩次,則引發(fā) BadMethodCallException。 如果出現(xiàn)以下情況,則引發(fā) UnexpectedValueException 請求的 phar URL 格式不正確,請求的 無法打開 phar,或者在 Phar 中找不到文件。
示例 #1 A PharFileInfo::__construct() example
<?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";
}
// this also works
$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 operations failed: ', $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
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: