本文介绍了获取Phar存档中当前文件的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习 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存档中当前文件的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 22:28