PHP DateTime class Namespace
I'm use the symfony2
framework and I want to use the PHP's DateTime class (PHP version is 5.3).
Here the statement:
namespace SDCU\GeneralBundle\Entity;
class Country
{
public function __construct(){
$this->insertedAt = new DateTime();
}
}
But, when execute this
constructor, I get an error saying that there's no
"SDCU\GeneralBundle\Entity\DateTime" class. I've been searching
around for DateTime's namespace but with no success... any idea?
Answer:
DateTime
is in the global namespace, and as "classnames always resolve to the current namespace name" you have to use \DateTime
.
COMMENTS