Like C++, PHP Namespaces are the way of encapsulating items so that same names can be reused without name conflicts.
- It can be seen as an abstract concept in many places. It allows redeclaring the same functions/classes/interfaces/constant functions in the separate namespace without getting the fatal error.
- A namespace is a hierarchically labeled code block holding a regular PHP code.
- A namespace can contain valid PHP code.
- Namespace affects following types of code: classes (including abstracts and traits), interfaces, functions, and constants.
- Namespaces are declared using the namespace keyword.
A namespace must be declared the namespace at the top of the file before any other code – with one exception: the declare keyword.
If namespace is declared globally, then declare it without any name.
Multiple namespaces can be declared within a single PHP code.
A namespace is used to avoid conflicting definitions and introduce more flexibility and organization in the code base. Just like directories, namespace can contain a hierarchy know as subnamespaces. PHP uses the backslash as its namespace separator.
Aliasing in Namespaces
Importing is achieved by using the ‘use’ keyword. Optionally, It can specify a custom alias with the ‘as’ keyword.
It is possible to dynamically call namespaced code, dynamic importing is not supported.
Reference : http://php.net/manual/en/language.namespaces.php
- jQuery | event.namespace Property
- Difference between iCloud and Amazon Drive
- Difference between Dropbox and Amazon Drive
- Difference between Dropbox and iCloud
- Difference between OneDrive and iCloud
- Difference between OneDrive and Amazon Drive
- How to add custom google search bar inside your web-page?
- How to create Animated Blur Navbar using CSS?
- How to fade in color button from btn-primary to btn-success?
- Materialize CSS | Tables
- SASS | Style Rules
- How to define superscripted text using HTML5 ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.