- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP Declaring sub-namespaces
Introduction
It is possible to create namespaces inside a namespace. Just as a directory in file system can contain sub directories in a heriarchical structure, sub-namespaces can be arranged in hierarchy. The backslash character \ is used to define the relationship between top level and sub-level namespace,
In this example toplevel namespace myspace contains two sub-namespaces space1 and space2. In order to access functions/classes inside a subnamespace, first make it available by use keyword
Example
<?php namespace myspace\space1; function hello() { echo "Hello World from space1
"; } namespace myspace\space2; function hello(){ echo "Hello World from space2
"; } use myspace\space1; hello(); use myspace\space2; hello(); ?>
Output
Above code shows following output
Hello World from space2 Hello World from space2
- Related Articles
- PHP Namespaces Overview
- PHP Using namespaces
- PHP Aliasing/Importing namespaces
- PHP Defining Multiple Namespaces in same file
- Sort php multidimensional array by sub-value in PHP
- Is it possible to get list of defined namespaces in PHP
- What are namespaces in C#?
- Namespaces and Scoping in Python
- Namespaces and Scope in Python
- Declaring a Fallback Color in CSS
- How to define namespaces in C#?
- What are nested namespaces in C#?
- Can namespaces be nested in C++?
- How to use namespaces in C++?
- What are Python namespaces all about?

Advertisements