问题描述
我目前正在学习 PHP档案(Phars),我知道在PHP中__FILE__
始终是当前执行文件的绝对文件名.
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.
但是,如果脚本位于Phar中,则__FILE__
指向哪个文件?是Phar本身的绝对文件名,还是Phar中当前脚本的Phar-URL?
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?
例如:如果我有一个位于/path/to/my.phar
的Phar,其中包含一个存根脚本,一个PHP脚本位于phar:///path/to/my.phar/inside/inner.php
. __FILE__
在存根和inner.php
中是什么?
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
?
推荐答案
您可以自己尝试一下.
简短的答案是__FILE__
具有完整路径;是
The short answer is that __FILE__
has the full path; it's
phar:///home/cweiske/Dev/test/phar/test.phar/path/to/foo.php
在我的测试案例中-参见 http://p.cweiske.de/172
in my test case - see http://p.cweiske.de/172
这篇关于获取Phar存档中当前文件的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!