• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • Phar::interceptFileFuncs()

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

    Instructs phar to intercept fopen, file_get_contents, opendir, and all of the stat-related functions

    说明

    finalpublicstaticPhar::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.

    返回值

    范例

    A Phar::interceptFileFuncs() example

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

    Assuming that this phar is at/path/to/myphar.pharand it containsfile.phpandfile2.txt, iffile.phpcontains this code:

    A Phar::interceptFileFuncs() example

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

    Normally PHP would search the current directory forfile2.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 bephar:///path/to/myphar.phar/and so opensphar:///path/to/myphar.phar/file2.txtin the above example code.