PHP class loading problem background: scan all the classes that inherit a base class under a folder (including subfolders), include them in, instantiate and call a method to save the data in the database!
Problem: if there are classes with the same class name under two different subfolders, there will be a problem with include, and PHP should be confused in new versions.
Beginner, please refer
Reply to discussion (solution)
Yes! Problems may occur.
Therefore, the concept of "namespace" was introduced in php 5.3.
Classes of the same name in different namespaces do not conflict.
Yes! Problems may occur.
Therefore, the concept of "namespace" was introduced in php 5.3.
Classes of the same name in different namespaces do not conflict.
Will I be confused when I am new, because the class names of the two classes are the same and there are the same methods, that is, can I specify the namespace when I am new?
Yes. you can specify the namespace when using new.
Namespace. classname = new namespace. classname