This allows you to have classes with the same name even in the same folder. Here is a sample code.
file name: namespace.php
<?php namespace MyProject { class Connection { public function __construct(){ echo 'My Project class call'; } } function connect() { echo 'My Project connect function.'; } } namespace AnotherProject { class Connection { public function __construct(){ echo 'Another Project class call'; } } function connect() { echo 'Another Project connect function.'; } } ?>
Another file where we use this namespace. file name: myapp.php
<?php require 'namespace.php';
source share