The code under the Tool.class.php file is:
namespace CompanyTool;
class Tool{
}
My question is why if you use the Tool class in other files, you must write like this: use Company\Tool\Tool
I thought it would be enough to write use Company\Tool (what I understand means that you can use any class in this space).
I hope you can tell me, thank you.
C++ has what you want
using namespace xxx
.Why PHP doesn’t directly introduce the entire namespace? Only those involved in the design probably know this.
I guess the reason is to avoid introducing too many unnecessary things at once. Batch introduction is not recommended in various languages.
Accurate to class can improve performance. If it is only accurate to a certain directory, every time a class is loaded, the compiler still needs to go to the directory to find whether the class exists.
Accurate to the class to avoid conflicts. If the same class name exists in two directories, if it is accurate to the class, conflicts can be avoided very well.
Easy to optimize, C# has the features mentioned by the poster, but C# is directly compiled into an executable file, but Java adopts a class-accurate approach, both are interpreted languages, and the benefit of this is beneficial to the later stage. Interpretation optimization allows classes to be found accurately and reduces cache consumption.
You can use a class or a namespace
Quote
or
If you write it like that,
autoload
will definitely not be able to find this file. If the file is loaded manually, it must be written that way based on the understanding of the namespace. And I think the layout of the question should benamespace CompanyTool;
right