Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SilvioDev's avatar

Non-static method

I have in my User model a function "findWithEmailOrBenutzername($data)" and it returns the user. Now when i try to get the user from a Controller for example like $user = $User::findWithEmailOrBenutzername($data); i get the message "Non-static method, User::findWithEmailOrBenutzername() should not be called statically, assuming $this from incompatible context ".

How can i fix this problem?

0 likes
3 replies
jekinney's avatar

When you use Model::method() is called a static method. So the method should read: public static function method() In your case either add the static key word or inject the model in your controller function. Then call it like: $model->method().

If this is confusing you need a bit more reading on static and non-static methods. In OOP it is a basic level.

Please or to participate in this conversation.