PHP Conference Japan 2024

PharFileInfo::getMetadata

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

PharFileInfo::getMetadata傳回儲存於檔案的檔案特定中繼資料

說明

public PharFileInfo::getMetadata(陣列 $unserializeOptions = []): 混合

傳回由此檔案的 Phar 封存檔資訊清單中儲存的元資料。

參數

傳回值

任何可以序列化並儲存為檔案元資料的 PHP 變數,如果沒有儲存元資料,則為 null

更新日誌

版本 說明
8.0.0 新增了 unserializeOptions 參數。

範例

範例 #1 PharFileInfo::getMetadata() 範例

<?php
// 確定它不存在
@unlink('brandnewphar.phar');
try {
$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar', 0, 'brandnewphar.phar');
$p['file.txt'] = 'hello';
$p['file.txt']->setMetadata(array('user' => 'bill', 'mime-type' => 'text/plain'));
var_dump($p['file.txt']->getMetadata());
} catch (
Exception $e) {
echo
'無法建立/修改 brandnewphar.phar: ', $e;
}
?>

以上範例將輸出

array(2) {
  ["user"]=>
  string(4) "bill"
  ["mime-type"]=>
  string(10) "text/plain"
}

參見

新增註記

使用者貢獻的註記

此頁面沒有使用者貢獻的註記。
To Top