Phar::isValidPharFilename

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

Phar::isValidPharFilename指定したファイル名が正しい形式の phar ファイルかどうかを返す

説明

final public static Phar::isValidPharFilename(string $filename, bool $executable = true): bool

指定したファイル名のファイルが、phar 拡張モジュールで利用できる 正しい形式の phar ファイルであるかどうかを返します。 これは、phar アーカイブを実際に開く前にそのファイルを確認する際に使用します。 これで、 無効なファイルを指定したときに当然発生するであろう例外の処理を省略することができます。

パラメータ

filename

まだ作成されていない phar アーカイブの名前あるいはフルパス。

executable

このパラメータは、指定した名前のファイルを phar の実行可能アーカイブとして扱うかデータのみの非実行可能アーカイブとして扱うかを指定します。

戻り値

正しい形式のファイルである場合に true、そうでない場合に false を返します。

add a note

User Contributed Notes 2 notes

up
0
kevin dot sours at internetbrands dot com
16 days ago
This appears to return true for the running phar file regardless of the file extension. This is undocumented (as is the fact that PHP will run phar files perfectly fine with a php extension). This allows, for instance, reading the metadata for the running phar.
up
0
sebastian dot krebs dot berlin at googlemail dot com
12 years ago
Note, that this method accepts _everything_ (=> returns 'true'), when $executable is 'false' as long as the filename contains at least a dot

var_dump(\PharData::isValidPharFilename('randomstring.y', false));
bool(true)

This is not wrong at all, because I can name an archive like I want, but it makes the method completely useless (when $executable == false).
To Top