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

WBOY
Release: 2016-06-23 13:40:39
Original
930 people have browsed it


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
这是一个查找次序的问题

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!