0

我有一个关于 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 环境

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

视窗环境

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 错误还是什么原因造成的?

4

1 回答 1

-1

不,这不是一个错误,它是窗口文件系统和 linux 文件系统之间的区别

于 2013-01-31T07:54:04.843 回答