PHP require_once fails but require works
In an application I am calling require_once $file where I have validated that the $file variable represents an absolute path, the file exists, and is readable. PHP 7.3 is giving me the dreaded: "Fatal error: require_once(): Failed opening required" message.
When I change the code to use "require" instead of "require_once" I get further, till the next "require_once" statement.
I am running PHP 7.2.19 on ubuntu 18.04.
This particular code is embedded deep within an application that has already included and required many different files at different times.
I have checked for obvious things like the particular file being included multiple times (it is not)... and including a different file for testing purposes, and that also consistently fails. I have double checked permissions, etc.
$file = "$destdir/lib/include.php";
$file = realpath($file);
if( is_file($file) && is_readable($file) ) {
require_once $file; // fails
// require $file; // works, but fails when require_once is called within this file.
// include $file; // works, but fails when require_once is called within this file
// include_once $file; // fails
}
I expected of course, that the file is required.