菲律宾比索 spl_autoload_register
2022-08-30 14:50:17
我正在尝试利用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');
一切似乎都很好,但我只是想仔细检查一下,这确实被认为是可以接受的做法。