Phar::interceptFileFuncs

(PHP 5 >= 5.3.0, PHP 7, PECL phar >= 2.0.0)

Phar::interceptFileFuncsInstructs phar to intercept fopen, file_get_contents, opendir, and all of the stat-related functions

说明

final public static Phar::interceptFileFuncs ( void ) : void

instructs phar to intercept fopen(), readfile(), file_get_contents(), opendir(), and all of the stat-related functions. If any of these functions is called from within a phar archive with a relative path, the call is modified to access a file within the phar archive. Absolute paths are assumed to be attempts to load external files from the filesystem.

This function makes it possible to run PHP applications designed to run off of a hard disk as a phar application.

参数

No parameters.

返回值

范例

Example #1 A Phar::interceptFileFuncs() example

<?php
Phar
::interceptFileFuncs();
include 
'phar://' __FILE__ '/file.php';
?>

Assuming that this phar is at /path/to/myphar.phar and it contains file.php and file2.txt, if file.php contains this code:

Example #2 A Phar::interceptFileFuncs() example

<?php
echo file_get_contents('file2.txt');
?>

Normally PHP would search the current directory for file2.txt, which would translate as the directory of file.php, or the current directory of a command-line user. Phar::interceptFileFuncs() instructs PHP to consider the current directory to be phar:///path/to/myphar.phar/ and so opens phar:///path/to/myphar.phar/file2.txt in the above example code.

相关文章
php eventbuffer write contents of the buffer to a file or socketphp apc 函数 stores a file in the bytecode cache bypassing all filtersphp direct io 函数 opens a file creating it if necessary at a lower level than the c library input/ouput stream functions allowphp oci8 obsolete aliases and functions 别名 oci fetch allphp svn 函数 copies a file or a directory returns true if all is ok false otherwisephp svn 函数 deletes a file or a directory return true if all is ok false otherwisephp gearmanclient clear all task callback functionsphp oci lob exports lob s contents to a filephp phar compresses all files in the current phar archive using bzip2 compressionphp phar compresses all files in the current phar archive using gzip compressionphp phar decompresses all files in the current phar archivephp phar extract the contents of a phar archive to a directoryphp what makes a phar a phar and not a tar or a zip? ingredients of all phar archives independent of file formatphp phar instructs phar to intercept fopen file get contents opendir and all of the stat related functionsphp phar reads the currently executed file a phar and registers its manifestphp phar mount an external path or file to a virtual location within the phar archivephp phar determines whether a file exists in the pharphp phar set the contents of an internal file to those of an external filephp phar uncompresses all files in the current phar archivephp phardata convert a phar archive to a non executable tar or zip file
关注编程学问公众号