Non-Static Method Should not be Called Statically

I just ran into the non-static method should not be called statically error when building out some functionality for a client. In short, I needed to instantiate the class that I was using before running one of those class’ methods. See the initial code that threw the error and the code that fixed it below:

Incorrect Code that threw the non-static method should not be called statically error

$subscribers = ServiceClass::getSubscribers();

Correct Code that fixed the error

$service = new ServiceClass();
$subscribers = $service->getSubscribers();

Leave a Reply

Your email address will not be published. Required fields are marked *