简体   繁体   中英

PHP include_once fails without warning or error for an existing file

Got me an error thats got me stumped. Am trying to implement a custom class loader in php. Am on version 5.6.11. The problem is that I am building up the path to a file dynamically and then doing an "include_once" on that path. PHP is just terminating execution at that point with no warnings or error messages. The path is valid. The code is basically like this

require_once "lib/includes/web/classloader/default.php";
require_once "lib/includes/web/controller/default.php";
$classloader = new web\classloaders\ClassLoader();
$controller_path = $classloader->registerController();
if($controller_path != null){
    require_once("$controller_path");
}

The file_exists and is_readable checks are done in the registerController() function of the class loader.

I have also tried this:

require_once $controller_path;

and this:

require_once($controller_path);

Any ideas?

regards

There is no problem with the syntax as I tested with the code. The problem should be on the path. Try using echo $controller_path; die(); echo $controller_path; die(); before using require_once to see the path.

OR

You can insert

error_reporting(E_ALL); ini_set("display_errors", 1);

at the beginning of the PHP page to enable error display so that you can see what is causing the error..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM