simple PHP namespace example

Foo.class.php
class Foo
{
function Simple()
{
$var = “Hello”;
return $var;
}
}

namespace.php
namespace Second;
include(‘Foo.class.php’);

class Foo
{
function Simple()
{
$var = “Hello in Second Namespace<br />”;
return $var;
}
}

$fooSecond = new \Second\Foo();
echo $fooSecond->Simple();
//option 1
//$fooFirst = new \Foo();
//$fooFirst->Simple();
//option 2

echo \Foo::Simple();

Comments are closed.