Home Tutorial Php Phpnamespace Tutorial Multiple Namespace

 
 

Share on Google+Share on Google+
Multiple Namespace
Posted on: April 1, 2010 at 12:00 AM
Advertisement
In this tutorial we will study about multiple namespace declaration in PHP, how to declare namespace in PHP, how to access etc. Examples will make this clearer.

Defining multiple namespace in a single file:

In a single PHP file we can declare more than one namespace. PHP allow two syntaxes to declare more than one namespace in a single file. But it is not recommended to declare more than one namespace in a single file.

It is strongly discouraged to combine multiple namespaces into the same file.

No coding should write outside the namespace brackets except the declare statement.

Following code will not produce any output and no error report will be generated but this kind of coding is not advisable. 

Example:

<?php

namespace mySpace;

function myFunction()

{

echo __FUNCTION__;

}

class One

{

function myMethod()

{

echo __METHOD__;

}

}

namespace newspace;

class Two

{

function secondMethod()

{

echo __METHOD__;

}

}

?>

 

Output:

Advertisement

Related Tags for Multiple Namespace:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 1, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com