Home Tutorial Php Phpnamespace Tutorial Calling Namespace

 
 

Share on Google+Share on Google+
Calling Namespace
Posted on: April 1, 2010 at 12:00 AM
Advertisement
In this tutorial we will study about namespace declaration and calling from other file in PHP, how to call a namespace in PHP, how to access from outside the file etc. Examples will make this more clear.

Calling Namespaced Code From Other File:

In the previous tutorial we have seen that how to declare a namespace and how to access the class, function from inside the code, now in this current tutorial we will study how to access those class and function from other file.

Example:

Lib1.php

<?php

namespace mySpace;

function myFunction()

{

echo __FUNCTION__;

}

class One

{

function myMethod()

{

echo __METHOD__;

}

}

?>

Lib2.php

<?php

header('content-type:text/plain');

include('Lib1.php');

echo mySpace\myFunction()."\n";

echo mySpace\One::myMethod();

?>

Output:

mySpace\myFunction
mySpace\One::myMethod
Advertisement

Related Tags for Calling 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