- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
对我来说看起来一样,但我不确定,
因为有很多项目使用dirname(__FILE__)
。
最佳答案
他们的结果完全一样 ;所以,没有区别。
例如以下两行:
var_dump(dirname(__FILE__));
var_dump(__DIR__);
两者都会给出相同的输出:
string '/home/squale/developpement/tests/temp' (length=37)
但是,至少有两个区别:
__DIR__
仅存在于 PHP >= 5.3
dirname(__FILE__)
被更广泛使用的原因__DIR__
在编译时进行评估,而 dirname(__FILE__)
表示函数调用和在执行时评估
__DIR__
(或者,应该) 更快。
作为引用,请参阅 Magic constants手册部分(引用):
__DIR__
: The directory of the file.
If used inside an include, the directory of the included file is returned.
This is equivalent todirname(__FILE__)
.
This directory name does not have a trailing slash unless it is the root directory.
(Added in PHP 5.3.0.)
关于php - PHP 中的 __DIR__ 和 dirname(__FILE__) 有什么区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2749416/
我是 Django 项目的初学者。Django 项目的 settings.py 文件包含这两行: BASE_DIR = os.path.dirname(os.path.dirname(os.path.
如何获取我的 Crystal 脚本的编译版本以获取它自己的 __FILE__。这是一个例子。我有一个名为 ~/test.cr 的文件,其中包含以下内容: puts __FILE__ 我通过 Cryst
这个问题已经有答案了: What's the difference between __PRETTY_FUNCTION__, __FUNCTION__, __func__? (5 个回答) 已关闭 6
有没有更好的方法来打印 __file__ 而无需扩展名? import os print os.path.splitext(__file__)[0] 最佳答案 您可以使用 string.split,但
在线程中的if语句中使用__file__时出现错误,代码如下: import os from threading import Thread def cur_dir(): current_di
如果我在下面这样做: #include int main() { printf ("%s\n",__FILE__); return 0; } >gcc cfilename.c >./a.out
我知道在 Ruby 中 __FILE__ 指的是当前文件,但是在创建这样的路径时它指的是什么,为什么需要它作为 expand_path 的第二个参数? set :views, File.expand_
我有十几个脚本,我在其中重复这个 # caller.py THIS_FILE_DIR = os.path.dirname(os.path.realpath(__file__)) relative_pa
我想在我的模块 m 中定义一个效用函数 f() 这样 如果在/foo/a.py中调用m.f(),它返回/foo/a.py 如果在/bar/baz/b.py中调用m.f(),它返回/bar/baz/b.
我正在使用 WAMP 并在 www 目录中有一个开发站点。我想使用 dirname(__FILE__) 来定义服务器根目录的路径。 目前我使用的配置文件包含: define('PATH', dirna
我正在使用 DPRINTF(ERROR_LEVEL,"ERROR: error found at file: %s line: %d",__FILE__,__LINE__); 它像这样打印 ERROR
我正在使用 PHP 解压缩 PHP 应用程序本身的更新。这是通过从更新服务器抓取一个 zip 文件,将其解压缩,然后递归地将解压缩的文件移动到应用程序当前存在的文件上来完成的。 问题是下次我去使用该应
我正在尝试编写一种可以在使用文件完整路径的扩展类中使用的方法。但是,当我使用 __FILE__ 时,我只会返回定义继承方法的类的路径。这是一个示例: foo.php class foo { p
这个问题在这里已经有了答案: What method can I use instead of __file__ in python? (2 个答案) 关闭 5 年前。 情况是: python 嵌入
我发现我经常使用这种模式: os.path.join(os.path.dirname(__file__), file_path) 所以我决定在一个包含许多此类小实用程序的文件中放入一个函数: def
C 中可用的标准预定义宏 __FILE__ 显示文件的完整路径。有什么办法可以缩短路径吗?我的意思是代替 /full/path/to/file.c 我明白了 to/file.c 或 file.c 最佳
我有来自 Codeigniter index.php 的以下代码 我的理解是, 如果 $system_folder(在本例中为 CIcore_1_7_1)中字符串位置的 / 为 false,如果 re
谁能告诉我这两种方法中的任何一种是否比另一种有优势,为什么? $mydir = ABSPATH.'/wp-content/themes/mytheme/images'; $mydir = dirnam
我在将一些东西从 Solaris 移植到 Linux 时遇到的一个问题是 Solaris 编译器在预处理期间将宏 __FILE__ 扩展为文件名(例如 MyFile.cpp),而 Linux 上的 g
__FILE__表示当前所在文件的绝对路径包括文件名,dirname(__FILE__)表示当前文件的绝对路径,basename(__FILE__)表示当前文件的文件名称,dirname(__FIL
我是一名优秀的程序员,十分优秀!