Share on Google+Share on Google+

Calling Namespace

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

Advertisements

Advertisement

Posted on: April 1, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.