Error: call to a member function dispatch() on null