Relative includes and include_path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

On the the include_path php.net says:

"Using a . in the include path allows for relative includes as it
means the current directory. However, it is more efficient to
explicitly use include './file' than having PHP always check the
current directory for every include. "

(http://www.php.net/manual/en/ini.core.php#ini.include-path)

While this does not state that starting every include with "./" is
equivalent to having an include_path that is ".", it does suggest
exactly that.

However, I tried this in the field, and came to a different
conclusion. (I included my experiment below.)

Is the idea that those two are equivalent wrong?
Am I doing something wrong?
Is something strange going on?

Can anyone clear this issue up for me?

Thanks,

Jasper

---

The experiment:

On a machine where the include_path is ".", I had the following file structure:

- A.php
- B.php
- C.php
- file.php
- sub/includeA.php
- sub/includeB.php
- sub/includeC.php

The content of the files:

A.php
<?php

include 'file.php'

?>

B.php
<?php

include './file.php'

?>

C.php
<?php

include './../file.php'

?>


file.php
<?php

echo "Included successfully!";

?>

includeA.php
<?php

include '../A.php'

?>

includeB.php
<?php

include '../B.php'

?>

includeC.php
<?php

include '../C.php'

?>

Now if you visit A.php or B.php the file will be included
successfully. Obviously, C.php fails to include anything.
includeA.php works all the same, but includeB.php can't find file.php.
includeC.php, on the other hand, finds it just fine.

This would suggest that include_path being "." means you can include
from the path of the current file, while starting your "./" means you
start looking from the current parh.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux