I have a habit of using include() a lot in my php scripts. I would like to know is it a good approach. I just use include a lot because it makes code look-better for future-
If you're developing object-orientated and have a file for each class, consider implementing an autoloader function that automatically calls include
when a class is used but not yet loaded:
$callback = function($className) {
// Generate the class file name using the directory of this initial file
$fileName = dirname(__FILE__) . '/' . $className . '.php';
if (file_exists($fileName)) {
require_once($fileName);
return;
}
};
spl_autoload_register($callback);