Given a PHP application with the following structure:
/
lib/
mylib.php
web/
index.php // includes "mylib.php" with: require_once __DIR__ . "/../lib/mylib.php"
I am trying to cover the following cases at the same time with the same source base:
In the case of phar files, all requests would be redirected to the phar file itself.
Is it possible to achieve all those use cases while not having to change the *require_once*?
I tried different approaches (relative/absolute) to include lib/mylib.php from *web/index.php", as well as trying some tricks with Phar::mount(). None of my attempts succeeded.
Simply rely on your include path.
Don't do:
require_once __DIR__ . "/../lib/mylib.php";
but:
require_once "mylib.php";
and set the include path at the beginning of your script:
set_include_path(__DIR__ . '/../lib/' . PATH_SEPARATOR . get_include_path());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With