Answer the question
In order to leave comments, you need to log in
Is it correct to consider static methods global along with their classes?
Hello! I read the documentation, but I still don't understand. If I create a class with static methods and a static parameter like this:
class Speedbar{
private static $data = [];
public static function getData(): array
{
return self::$data;
}
public static function setData(array $data): void
{
self::$data = $data;
}
}
Answer the question
In order to leave comments, you need to log in
Regarding Singletone.
Static methods cannot be declared in an interface, hence you are tied to a specific implementation. There is no such problem with singleton.
UPD : as indicated in the comments, it can still be done.
Static methods are harder to code for tests. With a singleton, everything will be easier here too.
Then it is not clear why singleton is needed if the class is already unique using only static methods
Is it correct to consider static methods global along with their classes?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question