PHP 8.1.28 Released!

Phar::mapPhar

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

Phar::mapPharLeer el fichero (un phar) que está en ejecución y registrar su manifiesto

Descripción

final public static Phar::mapPhar(string $alias = ?, int $dataoffset = 0): bool

Este método estático solamente se puede usar dentro de una rutina de interoperabilidad cargadora de un archivo Phar para inicializar el phar cuando sea directamente ejecutado, o cuando se incluya en otro scrip.

Parámetros

alias

El alias que puede usarse en las URL phar:// para referirse a este archivo, en vez de su ruta completa.

dataoffset

Variable sin uso, está aquí por compatibilidad con los PHP_Archive de PEAR.

Valores devueltos

Devuelve true en caso de éxito o false en caso de error.

Errores/Excepciones

Se lanza una excepción de tipo PharException si no se llama directamente dentro de la ejecución de PHP, si no se encuentra el token __HALT_COMPILER(); en el fichero fuente actual, o si el fichero no se puede abrir para lectura.

Ejemplos

Ejemplo #1 Un ejemplo de Phar::mapPhar()

mapPhar debería usarse dentro de una rutina de interoperabilidad cargadora de phar. Utilice loadPhar para cargar un phar externo en memoria.

Aquí está una rutina de interoperabilidad de Phar de muestra que usa mapPhar.

<?php
function __autoload($clase)
{
include
'phar://mi.phar/' . str_replace('_', '/', $clase) . '.php';
}
try {
Phar::mapPhar('mi.phar');
include
'phar://mi.phar/inicio.php';
} catch (
PharException $e) {
echo
$e->getMessage();
die(
'No se puede inicializar el Phar');
}
__HALT_COMPILER();

Ver también

add a note

User Contributed Notes 1 note

up
-1
phofstetter at sensational dot ch
10 years ago
Be careful with mapPhar and opcode caches like opcache: They might cache files included by the symbolic name based on the symbolic name you give.

This becomes a problem when a server is hosting multiple different versions of a phar file all using the same symbolic name because then subsequent include()'s in the phar file might load an already cached file from another version of the phar file.

Instead, generate a unique name and use that in mapPhar and in subsequent include()'s

See for example https://github.com/zendtech/ZendOptimizerPlus/issues/115#issuecomment-25612769 for the issue in the opcache module.
To Top