是否有任何理由在文件包含代码中使用__DIR__ ?


Is there any reason to use __DIR__ in the file inclution code?

是否有理由使用require_once( __DIR__.'/../../foo.php');而不是require_once('/../../foo.php') ?在一些第三方代码中,我看到使用__DIR__前缀指定路径。而.include_path中使用或不使用__DIR__在功能上是等同的。是否有理由使用__DIR__ ?

使用___DIR___是因为第三方代码无法控制您的include_path中是否有.___DIR___总是引用当前文件的目录(参见Magic Constants)。