Answer the question
In order to leave comments, you need to log in
Autoload obliges to specify namespace for all classes?
Today I got acquainted with the spl_autoload_register function . Its use implies two options:
A fully qualified class name must have the following structure: \<Namespace>(\<SubNamespace>)*\<ClassName>
Answer the question
In order to leave comments, you need to log in
1) From the point of view of programming standards, how correct is it to specify a namespace for each class?Yes, it is right. One file, one class, which must be in a specific namespace.
2) Which approach for using spl_autoload_register of the two listed is more correct?Second. Because this is the standard. " Calling several times, specifying functions that include classes from different directories as an argument " is when you have a mess of code and you are trying to pull it all into modern realities.
php ../composer.phar init
{
.....
"autoload": {
"psr-4": {
"App\\": ["app/"]
}
}
}
php ../composer.phar dump-autoload
require('./vendor/autoload.php');
to the index file or to those files where classes with autoloading are needed. From the point of view of programming standards, how correct is it to specify a namespace for each class?
After all, you can easily get confused in this way, and the code begins to contain characters that it could have passed before.
Which approach for using spl_autoload_register of the two listed is more correct
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question