Skip to main content
Source Link
Ryan
  • 721
  • 1
  • 10
  • 14

Component functions - static vs. OO?

I'm writing a small PHP framework to help me develop Web applications. The framework is split into numerous components, each of which are automatically loaded according to the configuration settings. This is my component base class:

class Component {
    public static void init() {}
}

When I create new components, I extend them from Component. For example, I have an Authenticator component that handles user login, logout and some other related functions. Here's an example of the code:

class Authenticator extends Component {
     public static void login($u, $p) {}
     public static void logout() {}
     ...
}

As you can see my methods are static, so when it comes time to use the component, I can easily call the component's functions using Authenticator::METHOD() in the scope of my controller class. There is no need to create an instance of the components since they are in a static context.

But should I make them more OO (eg: make the methods non-static) using DI or some other means? What would be the advantages of this? And considering how I have several components, how would I do this without making things overly complex?