Namespace

 <?php

// THIS IS INDEX FILE

require "products.php";
require "testing.php";

function wow()
{
    echo "Wow from Index File". "<br>";
}

$object = new test\Product();
$object = new pro\Product();

wow() . "<br>";
pro\wow() . "<br>";
?>
//  OUTPUT:
// This is testing page class
// This is product Class
// This is testing page class
// Wow from Index File
// Wow from Product File


<?php
//  THIS IS TESTING FILE

namespace test;

class Product
{
    public function __construct()
    {
        echo "This is testing page class" . "<br>";
    }
}
?>



<?php
//  THIS IS PRODUCTS FILE

namespace pro;

class Product
{
    public function __construct()
    {
        echo "This is product Class" . "<br>";

        $test = new \test\Product();
    }
}
function wow()
{
    echo "Wow from Product File" . "<br>";
}

?>

//  OUTPUT:
// This is testing page class
// This is product Class
// This is testing page class
// Wow from Index File
// Wow from Product File

Comments

Popular posts from this blog

Ajax Insert Records in Database Tutorial in PHP

Arithmetic Operators Tutorial in PHP

Displaying Database data using Class, Object, Constructor, Destructor in PHP MySql