PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Phar::offsetSet> <Phar::offsetExists
Last updated: Fri, 10 Oct 2008

view this page in

Phar::offsetGet

(PECL phar:1.0.0-1.2.1)

Phar::offsetGet指定したファイルの PharFileInfo オブジェクトを取得する

説明

int Phar::offsetGet ( string $offset )

これは ArrayAccess インターフェイスを実装したものです。 これにより、Phar アーカイブの内容に対して配列形式の角括弧を使用したアクセスが可能となります。 offsetGet を使用して、Phar アーカイブからファイルを取得します。

パラメータ

offset

Phar 内で探すファイル名 (相対パス)。

返り値

PharFileInfo オブジェクトを返します。 これを使用して、ファイルの内容を順に処理したりファイルの情報を取得したりします。

エラー / 例外

そのファイルが Phar アーカイブ内に存在しない場合に、このメソッドは BadMethodCallException をスローします。

例1 Phar::offsetGet() の例

ArrayAccess インターフェイスを実装した他のクラスと同様、 offsetGet は [] 演算子を使用した場合に自動的にコールされます。

<?php
$p 
= new Phar(dirname(__FILE__) . '/myphar.phar'0'myphar.phar');
$p['exists.txt'] = "file exists\n";
try {
    
// 自動的に offsetGet() をコールします
    
echo $p['exists.txt'];
    echo 
$p['doesnotexist.txt'];
} catch (
BadMethodCallException $e) {
    echo 
$e;
}
?>

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

file exists
Entry doesnotexist.txt does not exist



add a note add a note User Contributed Notes
Phar::offsetGet
There are no user contributed notes for this page.

Phar::offsetSet> <Phar::offsetExists
Last updated: Fri, 10 Oct 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites