Answer the question
In order to leave comments, you need to log in
How to correctly implement autoloading in PHP without sacrificing the use of use?
I must say right away that I know about the possibility of using a composer. But I want to learn how to do it myself and then explore the ready-made tools.
My problem is that I wrote the following code:
function loader($class)
{
$class = str_replace('\\', '/', $class);
$file = SITE_PATH . DS . $class .".php";
if (file_exists($file)) {
include $file;
return true;
} else {
return false;
}
}
spl_autoload_register('loader');
$registry = new core\Registry();
spl_autoload_register('loaderControllers');
spl_autoload_register('loaderModels');
spl_autoload_register('loaderViews');
Answer the question
In order to leave comments, you need to log in
Reframe your question.
It's unclear.
Autoload and namespaces are not connected in any way, what exactly is the gag?
What means
I can't use use, which really annoys me.
"I have a suitcase full of tools. I need to tighten a bolt, but I can't sacrifice using a screwdriver."
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question