简体   繁体   中英

Get name of current file inside Phar archive

I'm currently learning about PHP archives (Phars) and I know that in PHP __FILE__ always is the absolute filename of the currently executing file.

But to which file does __FILE__ point to if the script is inside a Phar? Is it the absolute filename of the Phar itself, or the Phar-URL to the current script inside the Phar?

For example: If I have a Phar located at /path/to/my.phar which contains a stub script, and a PHP script located at phar:///path/to/my.phar/inside/inner.php . What would __FILE__ be in the stub and inner.php ?

You could have tried it yourself.

The short answer is that __FILE__ has the full path; it's

phar:///home/cweiske/Dev/test/phar/test.phar/path/to/foo.php

in my test case - see http://p.cweiske.de/172

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM