Tutorial by Examples

A namespace declaration can look as follows: namespace MyProject; - Declare the namespace MyProject namespace MyProject\Security\Cryptography; - Declare a nested namespace namespace MyProject { ... } - Declare a namespace with enclosing brackets. It is recommended to only declare a single na...
As shown in Declaring Namespaces, we can define a class in a namespace as follows: namespace MyProject\Shapes; class Rectangle { ... } To reference this class the full path (including the namespace) needs to be used: $rectangle = new MyProject\Shapes\Rectangle(); This can be shortened by ...
The PHP community has a lot of developers creating lots of code. This means that one library’s PHP code may use the same class name as another library. When both libraries are used in the same namespace, they collide and cause trouble. Namespaces solve this problem. As described in the PHP referenc...
To declare a single namespace with hierarchy use following example: namespace MyProject\Sub\Level; const CONNECT_OK = 1; class Connection { /* ... */ } function connect() { /* ... */ } The above example creates: constant MyProject\Sub\Level\CONNECT_OK class MyProject\Sub\Level\Connection...

Page 1 of 1