Heim  >  Artikel  >  Backend-Entwicklung  >  include文件,类or函数的相对路径是实例化页面还是文件页面?

include文件,类or函数的相对路径是实例化页面还是文件页面?

WBOY
WBOYOriginal
2016-06-23 13:40:39930Durchsuche


a.php::   include "b.class.php";

假设 b.class.php 的成员方法中有 相对路径;
如:  ./1.php  __FILE__ 等等; 

请问这些相对路径是相对于 源文件  还是 相对于a.php;

我用__FILE__ 和./1.php 测试,竟然是两种效果, 好乱, 

特此求问; 最好深点讲原理;


回复讨论(解决方案)

如果你在index.php里include 或require 其它文件!  那么 其它任何文件里的路径都是index.php所在路径!

不能绝对化了!
__FILE__ 是当前文件在文件系统中的位置,是绝对路径的。不在相对路径的讨论之列
 ./1.php 是相对路径,但你举的例子不能说明问题
如果这样 a.php::   include " b/b.class.php";
那么:这个 ./1.php 是相对 a.php 的,但是./1.php 不存在而  b/1.php 存在的话,那就是 b/1.php 了
因为 b/1.php 相对于 b/b.php 也是 ./1.php
这是一个查找次序的问题

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn