Why should we use static calls in PHP?

Why should we use static variables or static calls for static methods in PHP5? Maybe to increase productivity?

+4
source share
3 answers

We use static class variables to exchange data between all instances of the class, and we use static methods (preferably private static ) to compute something that is required for the functionality of the class, but regardless of the state of the class instance ( $this ).

Performance is not really the cause of static -s. This is more like a side effect.

+9
source

Using static classes allows you to better organize code and functions that should not be represented by their own instance. For example, factory classes, helper classes, ulitily classes, etc.

So, for example, you may have a set of utility functions that manage numbers. By placing them in the static "Math" class, you can group them together.

+5
source

With static calls, you don't need to instantiate the class to save some memory if you don't need the actual object.

+3
source

All Articles