Namespaces

Namespaces is a method with which we can group variable,function or objects so that we can have more than one variable or function or object with same name .

Namespaces were introduced into PHP from version 5.3 onwards

Example

<?php
namespace php;
class php
{
public function phpcodez()
{
echo ‘Function1 <br />’;
}
}
namespace codez;
class codez
{
public function phpcodez()
{
echo ‘Function2 <br />’;
}
}

$phpcodez = new phpphp();
$phpcodez->phpcodez();

$phpcodez = new codezcodez();
$phpcodez->phpcodez();

?>

Share

Leave a Reply

Your email address will not be published. Required fields are marked *