C
C
cybernoob2018-01-31 20:03:08
PHP
cybernoob, 2018-01-31 20:03:08

Question about static classes?

Quote:

Static classes do not use constructors. Therefore, each static method must do its own dependency checking, and the calling code must initialize all method parameters unless defaults are used.

1. If a class has a static method, what if the class cannot have a constructor?
2. What dependencies are we talking about? You can transfer everything you need to it
3.
the calling code must initialize all method parameters

Is it possible to access a class property inside a static class? for example$a = $this->var;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2018-01-31
@cybernoob

There is no concept of a static class. Properties or methods of a class can be static, but not the class itself.
1. A class can have a constructor, regardless of the presence of static methods.
2. A static method does not have access to class properties, so yes, it is necessary to transfer or pull up the dependencies of the method on the class there.
3. A static method cannot be accessed via $this.
PS: in other words - a static method is just a function that can be called without creating an object of that class, and a static property is a "static variable".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question