Created
September 28, 2013 03:35
-
-
Save ryanuber/6738085 to your computer and use it in GitHub Desktop.
PHP: "use" statement resolving both class and namespace in one statement. What if you have a namespace called `\fruit\apple`, and also a class called `\fruit\apple` ? If you do `use fruit\apple`, what does it "use" ? The answer is, both. It will now allow you to refer to both `apple` and `apple\...` as you please.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace fruit { | |
class apple { | |
public static $x = 'this is the apple class'; | |
} | |
} | |
namespace fruit\apple { | |
class seed { | |
public static $x = 'this is the seed class'; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use fruit\apple; | |
require 'test.php'; | |
print apple::$x . "\n"; | |
print apple\seed::$x . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The result of this gitst is: