I have built myself a PHP MVC framework to meet my needs. As pretty much all of the core classes are static, I just stumbled upon the idea of having static controllers. I know that for some reason static classes are not perceived well by programmers, however if a class makes no sense to have an instance I really can't see any good reason to create one.
For example the System
class ( b.k.a. App
in other frameworks ) that initializes the whole framework includes configuration files and calls the front controller. There cannot be two instances of this class - the system is only initialized once. Yes it does have other functions as well but none of them relate to an instance - getClientIP
, handleException
, handleError
etc.
So following the same path of logic, my controllers have no properties and are generally used once per request. However when I think about it, I have never seen a framework with static controllers. Static library classes - yes, but static controllers - never. Is there any good reason not to have static controllers in an MVC framework?
P.S.: And yes I know there's no such thing as static classes in PHP yet, basically what I call a static class is a class with private constructor and only static methods.