Skip to content

akaiserg/NameSpace-PHP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Namespaces in PHP

Namespaces give us a huge flexibility at the moment to define classes and their dependencies. For instance, by using namespaces you can finally have two classes with the same name( in different namespaces obviously) without any problem at all. In addition to this, Composer can resolve or map files with their namespaces avoiding the use of requires or require_onces on the files.

On the examples, each one work differently:

  • withOutComposer: This example doesn't use composer so to get the dependencies, it just uses requiere_once and some classes use the 'new' operator to work with their dependencies.

  • withComposer: The second one uses composer but it still has requires and use the 'new' operator.

  • withComposerDI: The last one uses composer, but at the same time the dependencies of each class are passed through the constructors, This way the code looks cleaner and it's easier to maintain.

Reference:

About

Example of namespaces in PHP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages