简体   繁体   English

获取Phar存档中当前文件的名称

[英]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. 我目前正在学习有关PHP档案(Phars)的信息,并且我知道在PHP中__FILE__始终是当前执行文件的绝对文件名。

But to which file does __FILE__ point to if the script is inside a Phar? 但是,如果脚本位于Phar中,则__FILE__指向哪个文件? Is it the absolute filename of the Phar itself, or the Phar-URL to the current script inside the Phar? 是Phar本身的绝对文件名,还是Phar中当前脚本的Phar-URL?

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 . 例如:如果我有一个位于/path/to/my.phar的Phar,其中包含一个存根脚本,一个PHP脚本位于phar:///path/to/my.phar/inside/inner.php What would __FILE__ be in the stub and inner.php ? 存根和inner.php中的__FILE__是什么?

You could have tried it yourself. 您可以自己尝试。

The short answer is that __FILE__ has the full path; 简短的答案是__FILE__具有完整路径; it's 它的

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

in my test case - see http://p.cweiske.de/172 在我的测试案例中-参见http://p.cweiske.de/172

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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