Skip to content

Instantly share code, notes, and snippets.

@quimo
Created January 10, 2020 10:06
Show Gist options
  • Save quimo/5862b37ebc3b4e7bac39e7caff038ec8 to your computer and use it in GitHub Desktop.
Save quimo/5862b37ebc3b4e7bac39e7caff038ec8 to your computer and use it in GitHub Desktop.
PHP Namespaces
<?php
namespace IFQ\project1;
class Project {
public function __construct() {
printf("Project1\n");
}
}
printf("namespaces/project1/project1.php\n");
$demo = new Project();
<?php
namespace IFQ\project2;
class Project {
public function __construct() {
printf("Project2\n");
}
}
printf("namespaces/project1/project1.php\n");
$demo = new Project();
<?php
include 'project1/project1.php';
include 'project2/project2.php';
printf("namespaces/projects.php\n");
$project = new IFQ\project1\Project();
$project = new IFQ\project2\Project();
use IFQ\project1\Project as Progetto;
use IFQ\project2\Project;
$project = new Progetto(); // Project1
$project = new Project(); // Project2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment