Question on static classes?

Quote:
In static classes don't use constructors. So each static method should fulfill check its dependencies, and the calling code needs to initialize all the parameters of the method, if you do not use the default values.


1. If the class has a static method the class can't be designer?
2. What kind of dependency is it? You can transfer everything you need

3.
the calling code needs to initialize all the parameters of the method

Inside of a static class you cannot refer to a class property? For example $a = $this->var;
June 8th 19 at 17:19
3 answers
June 8th 19 at 17:21
Solution
There is no concept of static class. Static can be properties or methods of the class but not the class itself.
1. The class can have a constructor, regardless of the presence of static methods.
2. A static method has access to properties of a class, so Yes, there it is necessary to pass or tighten Worte based on a method from a class.
3. From a static method cannot be referenced using $this.

PS: in other words - a static method is just a function that can be called without creating object of that class, a static property is a "static variable".
The concept is there.
Just PHP is not able. - otho.Mraz23 commented on June 8th 19 at 17:24
, okey, in PHP there is no such thing :-) - grady.Nad commented on June 8th 19 at 17:27
June 8th 19 at 17:23
Solution
PHP does not contain syntax static class.
However, you may still be able to have them by making the constructor private (private function __construct() {}), and all methods are static.
Inside of a static class you cannot refer to a class property.
Thank you. Than a private constructor differs from the usual? Why is it then at all, because static methods are callable without an instance of the class? - otho.Mraz23 commented on June 8th 19 at 17:26
making the constructor private, we prevent the creation of object of this class. Then this class can be used only in the context of static properties and methods. - grady.Nad commented on June 8th 19 at 17:29
,
Than a private constructor differs from the usual?

If the constructor is private it cannot be called to create the object. - shaniya commented on June 8th 19 at 17:32
June 8th 19 at 17:25
Solution
1. If the class has a static method the class can't be designer?

A static method does not make the class static. Formally you who does not forbid to implement the constructor in static classes, but they never will.

2. What kind of dependency is it? You can transfer everything you need

We are talking about internal dependencies. For example, the dB connection specified in the constructor will not be available.

Inside of a static class you cannot refer to a class property? For example, $a = $this->var;

Impossible. There is no object there is no pointer of $this. To access the properties used design self:$var. But that property was available - it must be previously defined right in the class. Consider static classes as sets of related functions.

z.s. Again, a static method or property in class, does not make this class static. For static classes never create instances.

Find more questions by tags PHP