Sub Namespace


 

Sub Namespace

In this tutorial we will study about sub namespace in PHP, how to declare namespace in PHP, how to access etc. Examples will make this clearer.

In this tutorial we will study about sub namespace in PHP, how to declare namespace in PHP, how to access etc. Examples will make this clearer.

Declaring sub-namespace:

We all are familiar with the directory structure or the tree of the file and folders, similarly we can get the nested or sub namespaces in PHP, this technique helps us to achieve more manageability. If you have done Java or C# before then this topic will be more easier.

The following example is illustrating the concept of this topic, no output will be generated.

Example:

<?php

namespace mySpace\FirstLevel\SecondLevel;

function myFunction()

{

echo __FUNCTION__;

}

class One

{

function myMethod()

{

echo __METHOD__;

}

}

 

?>

Ads