Thank you for this, but, sad to say I think it will not work. Because as far as I know, if __file__ is used, it will just tell the path of the current script.
It will not work if the case is like this:
A_file_with_an_unknown_path.inc file is located at "/unknown_root_dir/???/inc", and the file that will include the A_file_with_an_unknown_path.inc file is located at "/unknown_root_dir/???/script", then __file__ will then give a wrong filepath.
Assuming that
"/unknown_root_dir/???/" is the root for both directories, that is: if the relative path between the script that is being executed and the file_to_be_included is static... then you don't need an absolute path. Just use the static relative path.
Like, if I were to install your application at
/var/www/app/, the paths would be:
/var/www/app/scripts/currentScript.php
/var/www/app/inc/file_to_be_included.inc
But if I were to install it at
/home/username/app/, they would be:
/home/username/app/scripts/currentScript.php
/home/username/app/inc/file_to_be_included.inc
You could simply use the relative path:
"../inc/file_to_be_included.inc".
Unless the 'inc' directory and the 'scripts' directory can be installed in separate root directories?