0

I got a question regarding, PHP include path, it behaves differently in two environment.

Folder Structure:

Windows

|-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 Environtment

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 Environment

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)

I know the best practise is, it work in both platform

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

But I would like to know about this, is it a PHP bug or what cause this?

Shiro
  • 7,344
  • 8
  • 46
  • 80
  • Btw, `realpath()` only works on files that exist; i.e. it's not a string operation. – Ja͢ck Jan 31 '13 at 07:57
  • I can say for sure that `"/../parent/scripts/import.php"` will not work for either environment; did you make a typo? – Ja͢ck Jan 31 '13 at 08:15
  • Hi Jack, as I mention, the path is correct, I just want to know more why windows works (but not logically). From my understanding is ../ means referencing to the parent folder structure. – Shiro Jan 31 '13 at 08:24
  • Yes, `../` means parent, but `/../` means parent of root folder (which is the root folder itself). – Ja͢ck Jan 31 '13 at 08:29
  • Why do you need `realpath` in the first place? – PeeHaa Jan 31 '13 at 09:06
  • The reason I ask this because, my development is in Windows, which I had use the `/../`, but when I upload to my live server, it breaks, that why I found out something is not correct. It's make me come and clarify it. Obviously the only answer is windows file system and linux file system. – Shiro Feb 01 '13 at 00:49

1 Answers1

-1

no it is not a bug it is for difference between window file system and linux file system

mohammad mohsenipur
  • 3,218
  • 2
  • 17
  • 22