I have always used a singleton class for an object in PHP. As with all singleton classes, I think the main method looks like this:
class registry {public static function singleton} {if (! (!! (auto :: $ example)) {Self: $ example = new registry}} return self :: $ example;} public function doSomething () {echo 'something';}}
Class I want something like this:
Registry :: Singleton () -> doSomethine ();
Now me I do not understand what the difference is between the making of just a normal static function. If I use a normal constant square then will it create a new object.
class registry {Public static function doSomething () {echo 'some';}}
Now I can just use:
Can anyone explain to me that the function belongs to the singleton class. I really do not understand this.
A static function is a function that is an object of a class.
Registry :: doSomething ()
A singleton is a design pattern , which should prevent users from one of the classes By creating more instances, the class is therefore usually an example of only one singleton class. The singleton constructor should be declared private and there is a steady way to provide an instance object:
Class Singleton {Private Singleton () {} Private Static Ver $ Example = null; Public static getInstance () {if (self: $ example == zero) self: $ example = new singleton (); Return self: $ example; }}
For more information
PS: Sorry for my bad PHP, syntax can not be 100% correct, but you should understand it roughly What should I mean about the terms of OOP?
Comments
Post a Comment