php包含路径,通过使用..(双点)来引用

时间:2013-01-31 07:49:57

标签: php linux windows include realpath

我有一个问题,PHP包含路径,它在两个环境中表现不同。

文件夹结构:

|-C:\wamp\www\cms\themes\child
|-C:\wamp\www\cms\themes\parent

的Linux

|-/var/www/html/cms/themes/child
|-/var/www/html/cms/themes/parent

Linux Env​​irontment

var_dump(realpath('/')); // means /
var_dump(realpath('/../parent/scripts/import.php')); //boolean false
include('/../parent/scripts/import.php'); //it will not work
include('../parent/scripts/import.php'); //it will not work, except it will reference parent folder

Windows环境

var_dump(realpath('/')); //C:\
var_dump(realpath('/../parent/scripts/import.php')); //boolean false
include('../parent/scripts/import.php'); //am thinking it will work at first, but it does not work in windows (feel weird)
include('/../parent/scripts/import.php'); //it work in windows (feel weird)

我知道最佳做法是,它适用于两个平台

include(realpath(dirname(__FILE__)).'/../parent/scripts/import.php');

但我想知道这个,它是一个PHP错误或是什么导致这个?

1 个答案:

答案 0 :(得分:-1)

不是它不是窗口文件系统和linux文件系统之间差异的错误