I’m using the symfony2 framework and I want to use the PHP’s DateTime class (PHP version is 5.3).
Here the declaration:
namespace SDCU\GeneralBundle\Entity;
class Country
{
public function __construct(){
$this->insertedAt = new DateTime();
}
}
But, when executing 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?
DateTimeis in the global namespace, and as “class names always resolve to the current namespace name” you have to use\DateTime.Or import the package using: