PharFileInfo::__construct

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

PharFileInfo :: __ 구조 - Phar 항목 개체를 구성합니다.


설명

public PharFileInfo::__construct(string $filename)

이것은 직접 호출하면 안 됩니다. 대신 PharFileInfo 객체는 배열 액세스를 통해 Phar::offsetGet()을 호출하여 초기화됩니다.


매개변수

filename
파일을 검색하기 위한 전체 URL입니다. phar boo.phar에서 my/file.php 파일에 대한 정보를 검색하려면 항목이 phar://boo.phar/my/file.php여야 합니다.

오류/예외

__construct()가 두 번 호출되면 BadMethodCallException이 발생합니다. 요청한 phar URL의 형식이 잘못되었거나, 요청된 phar를 열 수 없거나, phar 내에서 파일을 찾을 수 없는 경우 UnexpectedValueException이 발생합니다.


Examples

예제 #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";
    }
    // 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