I have obtained several PHP files from a third party, all of which start with namespace. How can I use it? In addition, I want to use github. comjeremeamiasuper_closure I see useSuperClosureSerializer; however, Fatalerror: Class & #039; SuperC... I have obtained several PHP files from a third party, starting with namespace,
How can I use it?
In addition, what I want to use is
Https://github.com/jeremeamia/super_closure
Instructions
Use SuperClosure \ Serializer;
But the prompt
Fatal error: Class 'superclosure \ serializer' not found
If I add the same namespace to all my PHP files, I will report an error and cannot find the system's own PHP file.
Reply content:
I have obtained several PHP files from a third party, starting with namespace,
How can I use it?
In addition, what I want to use is
Https://github.com/jeremeamia/super_closure
Instructions
Use SuperClosure \ Serializer;
But the prompt
Fatal error: Class 'superclosure \ serializer' not found
If I add the same namespace to all my PHP files, I will report an error and cannot find the system's own PHP file.
Currently, third-party packages are widely used in php.composerYou can checkcomposerRelated usage and concepts
composer require jeremeamia/superclosure
If you want to use a file separately, you can directlyinclude. However, a package usually has many class files, and you don't plan to use them all.include--#
psr-4Is a load standardnamespaceCorresponds to a file path to achieve delayed loading on demand; UsecomposerInstallation, only onecomposerYou can implementpsr-4.
Of coursecomposerThere are many other functions ....
If your program is not usednamespaceAnd you need to usenamespaceFirst, make sure that these program files areincludeIn your program, you can directly use the full name of the corresponding class or useuseTo access these classes.
If you add the PHP file require_once () of namespace SuperClosure \ Serializer;, no error will be reported.
Namespace is used to register the path of a file. If you need to use a third-party class package, if your code supports the namespace autoload method, you need to add namespace to the relevant autoload. Different frameworks have different autoload methods. If not, you need to register your own autoload method. If you do not want to use the autoload method, you need to include each file you are using.