Search code examples
phpnamespacesnaming-conventionsphp-5.3

PHP namespace organisation, naming


I am facing the following problem :

  • I have a namespace Exception\*, which contains several types of exceptions.

  • I have a namespace Exception\User\*, which contains a specific kind of exceptions (Forbidden, LoggedOut...).

Where do I put the User base exception class, extended by Forbidden and LoggedOut :

  • Exception\User, i.e. in the Exception\* namespace (better full name) ?
  • Exception\User\User, i.e. in the Exception\User\* namespace (more consistent) ?
  • Exception\User\Exception, i.e. I rename it to be the "base" exception of the Exception\User\* namespace (weird) ?

NB : the User exception class is not abstract.

Precision : I've used an example with exceptions, this is just an example. I am really wondering about where to put/how to name a base class in a namespace tree.

Thanks if you can help me !


Solution

  • Exception\User
    Exception\User\Forbidden
    Exception\User\LoggedOut