Created
May 31, 2013 14:33
-
-
Save jlittlejohn/5685384 to your computer and use it in GitHub Desktop.
PHP: Namespacing
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 myNamespace; | |
class DateTime{ | |
public function customMethod(){ | |
return 'Fun Times'; | |
} | |
} | |
/* | |
* Create a new DateTime object that's in this current namespace | |
* If we are outside this namespace we can create it by: | |
* $customDate = new \myNamespace\DateTime(); | |
*/ | |
$customDate = new DateTime(); | |
echo $customDate->customMethod(); | |
/* We can still create the default DateTime object */ | |
$standardDate = new \DateTime(); | |
echo $standardDate->format('Y-m-d H:i:s'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment