我试图利用PHP中的自动加载.我在不同的目录中有各种类,所以我已经引导自动加载如下:
function autoload_services($class_name)
{
$file = 'services/' . $class_name. '.php';
if (file_exists($file))
{
require_once($file);
}
}
function autoload_vos($class_name)
{
$file = 'vos/' . $class_name. '.php';
if (file_exists($file))
{
require_once($file);
}
}
function autoload_printers($class_name)
{
$file = 'printers' . $class_name. '.php';
if (file_exists($file))
{
require_once($file);
}
}
spl_autoload_register('autoload_services');
spl_autoload_register('autoload_vos');
spl_autoload_register('autoload_printers');
Run Code Online (Sandbox Code Playgroud)
这一切似乎都很好,但我只想仔细检查这确实被认为是可以接受的做法.