Some people add basic classes like Exception, Throwable, DateTime etc to the namespace section like this:
<?php
namespace Foo\Bar;
use DateTime;
use Throwable;
Class MyClass{
public function getDate()
{
try {
new DateTime('Bizarre value');
} catch (Throwable $exception) {
//error handling
}
}
}
(new MyClass())->getDate();
But other people just add a slash in front of those basic classes:
<?php
namespace Foo\Bar;
Class MyClass{
public function getDate()
{
try {
new \DateTime('Bizarre value');
} catch (\Throwable $exception) {
//error handling
}
}
}
(new MyClass())->getDate();
What is the "canonical" one according to PSR?