Skip to content

Instantly share code, notes, and snippets.

@jlittlejohn
Created May 31, 2013 14:33
Show Gist options
  • Save jlittlejohn/5685384 to your computer and use it in GitHub Desktop.
Save jlittlejohn/5685384 to your computer and use it in GitHub Desktop.
PHP: Namespacing
<?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