I have always used the Singleton class for a registry object in PHP. Like all Singleton classes, I think the main method is as follows:
class registry
{
public static function singleton()
{
if( !isset( self::$instance ) )
{
self::$instance = new registry();
}
return self::$instance;
}
public function doSomething()
{
echo 'something';
}
}
Therefore, whenever I need something from a registry class, I use this function:
registry::singleton()->doSomethine();
Now I don’t understand what is the difference between creating a regular static function. Will it create a new object if I just use a regular static class.
class registry
{
public static function doSomething()
{
echo 'something';
}
}
Now I can just use:
registry::doSomethine();
Can someone explain to me what a function of one class is. I really don't get it.
source
share