How To Deal With Static Functions

I just realized that I created a lot of static functions. I heard that it is very bad practice. I been putting every function related with a User in the UserModel class. Everything function related with campaigns in my CampaignModel class etc… A lot of these functions I created use a query builder to get data instead of lazy loading because I need database performance. For example getLastCampaignsWithUsers(), getUsersWithAdvertisers(), getUsersInAllCampaigns() all use a query builder and don’t really rely on the model so they are technically static.

My question are:

Is it really bad to create a lot of static functions in your Model? (A lot of my functions are just database queries)

How do you guys go around this? Do you create another class? I like having any function that deals with each model in that model class and I like to share it everywhere.

Or should I just not call these functions static and just instantiate the class every time?:


$user = new User;

$user->getUsersWithAdvertisers(1);

instead of:


User::getUsersWithAdvertisers(1);

Static functions are just fine with your approach.

What i would do is rename them and drop the User from name since i know they are part of the User class, therefore it would be


User::getWithAdvertisers($id);

If you handle with the same data over and over again the same time, then I would consider calling them not statically and save (in between) results somewhere (in a property of the class for example), saving you from having too many queries.

PHP 5.5 will not allow you to call a static method in the context of its class; so: no, you are fine by calling them statically.