Skip to content

Instantly share code, notes, and snippets.

@aredridel
Created October 21, 2012 03:57
Show Gist options
  • Save aredridel/3925620 to your computer and use it in GitHub Desktop.
Save aredridel/3925620 to your computer and use it in GitHub Desktop.
include "MyStuff_MyClass.php";
include "MyClass.php";
new MyStuff\MyClass(); // prints "mine";
new \MyClass(); // prints "global";
new MyClass(); // Prints "global";
include "MyStuff_MyClass.php";
include "MyClass.php";
use MyStuff;
new MyStuff\MyClass(); // prints "mine";
new \MyClass(); // prints "global";
new MyClass(); // Prints "mine";
class MyClass {
function __construct() { echo "global"; }
}
<?php
namespace MyStuff {
class MyClass {
function __construct() { echo "mine"; }
}
}
new MyClass(); // prints "global";
new MyStuff\MyClass(); // prints "mine";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment