PHP 8.3.4 Released!

Phar::isValidPharFilename

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

Phar::isValidPharFilenameDétermine si le nom de fichier spécifié est un nom de fichier valide pour une archive phar

Description

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

Détermine si le nom de fichier spécifié est une nom de fichier valide pour une archive phar, qui sera reconnue comme telle par l'extension phar. Ceci peut être utilisé pour tester un nom sans avoir à instancier une archive phar et à attraper l'inévitable Exception qui sera levée si un nom de fichier non valide est spécifié.

Liste de paramètres

filename

Le nom ou le chemin complet vers une archive phar non encore créée

executable

Ce paramètre détermine si le nom de fichier doit être traité comme celui d'une archive phar exécutable ou comme une archive de données non exécutable.

Valeurs de retour

Retourne true si le nom de fichier est valide, false sinon.

add a note

User Contributed Notes 1 note

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