PHP namespaces and using the \ prefix in declaration
- by Jason McCreary
The following throws an error stating Exception can no be redeclared.
namespace \NYTD\ReadingListBackend;
class Exception extends \Exception
{
}
However, removing the \ prefix in the namespace declaration does not:
namespace NYTD\ReadingListBackend;
I recently adopted PHP namespaces. My understanding is that namespaces prefixed with \ are a fully qualified name.
So why can't I use the prefix in the namespace declaration? I can when referencing (e.g. new \NYTD\ReadingListBackend\Exception). Would appreciate a full explanation as I couldn't find anything in the docs.