Functions | |
load ($module, $path=null) | |
Variables | |
$current_path = "./" | |
load | ( | $module, | |
$path = null |
|||
) |
This is a function for loading a module relative to the current file in static context.
There is a problem about paths. When an HTTP is requested on http://localhost/folderA/index.php the current path is the real one matching folderA virtual one, say ./proyect/folderA/index.php.
If this index.php requires the file ./proyect/folderA/folderB/require1.php , require1.php is a module that uses the folderA path as current directory, not folderB, and it may require something from other folder like ./proyect/folderA/folderC/require2.php so, it will have:
This won't work... Because the current directory is the one matching the HTTP request virtual folder: ./proyect/folderA/ .
This is worse when require1.php is required by other PHP web page from other folder: If an HTTP request the http://localhost/index2.php and this index2.php requires ./project/folderA/folderB/require1.php, but require1.php wants the file on ../folderC/require2.php
, wich will points to ./proyect/../folderC/require2.php giving up with an error.
A mechanism that concatenates relative paths:
load("require1.php", "folderB/")
the current path should change to: "./folderB/".load("require2.php", "../folderC/")
the current paht should change to: "./folderB/../folderC/"$current_path = "./" |