I am writing a PHP interface and I am wondering whether I should have a namespace statement in that interface file.
So is it a good idea to have an interface within a namespace or should only the class implementing the interface be within a namespace? Or should they both have (different) namespaces?
Here is an example for an interface within a namespace:
<?php
namespace \Vendor\App\DatabaseAccess;
interface DatabaseAccessInterface
{
}
Here is an example for an implementation of that interface within the same namespace:
<?php
namespace \Vendor\App\DatabaseAccess;
class DatabaseAccess implements DatabaseAccessInterface
{
}
The interface and the class could be in the same namespace as in the examples or in different namespaces. Alternatively, the interface could leave out the namespace declaration alltogether. Which way is the most appropriate for code reusability and why?