PHP 8.5.0 Alpha 1 available for testing

Phar::isValidPharFilename

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

Phar::isValidPharFilenameDetermina si el nombre de fichero especificado es un nombre de fichero válido para un archivo phar

Descripción

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

Determina si el nombre de fichero especificado es un nombre de fichero válido para un archivo phar, que será reconocido como tal por la extensión phar. Esto puede ser utilizado para probar un nombre sin tener que instanciar un archivo phar y atrapar la inevitable Exception que será lanzada si se especifica un nombre de fichero no válido.

Parámetros

filename

El nombre o la ruta completa hacia un archivo phar no creado aún

executable

Este argumento determina si el nombre de fichero debe ser tratado como el de un archivo phar ejecutable o como un archivo de datos no ejecutable.

Valores devueltos

Devuelve true si el nombre de fichero es válido, false en caso contrario.

add a note

User Contributed Notes 2 notes

up
0
kevin dot sours at internetbrands dot com
11 months 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
13 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