PHPCon Poland 2024


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

Phar::isValidPharFilenameReturns whether the given filename is a valid phar filename


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

Returns whether the given filename is a valid phar filename that will be recognized as a phar archive by the phar extension. This can be used to test a name without having to instantiate a phar archive and catch the inevitable Exception that will be thrown if an invalid name is specified.



The name or full path to a phar archive not yet created


This parameter determines whether the filename should be treated as a phar executable archive, or a data non-executable archive

Valor Retornado

Returns true if the filename is valid, false if not.

add a note

User Contributed Notes 1 note

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));

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