I “require” a file that has its own call to require (). But calling set_include_path () does not work with the relative path in require (). Unfortunately, I do not control the required code file.
C: /myapp/index.php - My code
set_include_path(get_include_path() . ';C:/app/subfolder');
require('C:/app/subfolder/index.php');
C: /app/subfolder/index.php - third-party code (no control)
require('../config.php');
Result:
Failed to open window "../config.php" (include_path = '; C: / app / subfolder')
This does not work even if the C: / app / subfolder is in the include path. I would expect .. /config.php to be C: / app / subfolder /../ config.php. Maybe I'm doing it wrong.
In this case, C: /app/subfolder/index.php was not originally intended to be included in another PHP file. However, I am building the code in front of it, and I want C: /app/subfolder/index.php to still be able to require / include files as if it had never left its location.
I read that using dirname () or __DIR__ fixes the relative path problem in require () , but I cannot change the code in C: /app/subfolder/index.php .
Is there any way to make this work?
source
share