Is it correct to think static methods are global with their classes?

Hello! I read the documentation but did not understand. If I create a class with static methods and a static parameter, like so:
class Speedbar{

 private static $data = [];

 public static function getData(): array
{
 return self::$data;
}

 public static function setData(array $data): void
{
 self::$data = $data;
}

}


Happens I can call and change from any part of the web application? (including autoloading)
I have tried and do wherever I changed the setting data, in any php file it is changed.
Then it is not clear what singltone if the class is already unique using only static methods
April 19th 20 at 12:14
2 answers
April 19th 20 at 12:16
Regarding Singltone.

Static methods cannot be described in the interface, therefore you are tied to a specific implementation. With a singleton this is not a problem.
UPD: as pointed out in the comments - all the same it can be done.

Static methods are harder to sumocat for tests. With a singleton here, too, everything will be easier.
Thanks for the response. Why should singleton be described in the interface? Please give an example, I probably have something important missing - Dexter74 commented on April 19th 20 at 12:19
@Dexter74may be that the interface of the singleton one, but several different implementations - abbie commented on April 19th 20 at 12:22
Static methods cannot be described in the interface, therefore you are tied to a specific implementation


Em?
interface Example
{
 public static foo(): void;
}
- kayley80 commented on April 19th 20 at 12:25
@kayley80, still PROAP, Yes. - Clay31 commented on April 19th 20 at 12:28
a very strange answer. given that the singleton is always static, it turns out that one oil melanee other.
I'd like to have the same freedom of flight thoughts - isidro.Wintheiser commented on April 19th 20 at 12:31
@isidro.Wintheiser, no, well, generally true. Method of crutches and bike getInstance can return any implementation of the interface... on the other hand, it is not a singleton, and factory work.... - kayley80 commented on April 19th 20 at 12:34
April 19th 20 at 12:18
Then it is not clear why the need for a singleton, if the class is already unique using only static methods

Very starne question.

Singleton has nothing to do with the state of the class, but only to the number of instances. The singleton can only be one. It's such a crutch for procedural programming, for those who can not in the PLO.

In normal OOP singleton is not needed because the programmer is able to control how much and what kind of objects he has created, and not try to create a new object if you need have already been created.

Is it correct to think static methods are global with their classes?


Right. This is bad code, with very few exceptions.
In normal OOP singleton is not needed because the programmer is able to control how much and what kind of objects he has created, and not try to create a new object if you need have already been created.

Then will have to constantly transfer the objects from class to class - Dexter74 commented on April 19th 20 at 12:21
Oh! - isidro.Wintheiser commented on April 19th 20 at 12:24

Find more questions by tags PHP