According to the PHP manual, a class like this:
abstract class Example {}
cannot be instantiated. If I need a class without instance, e.g. for
If your class is not meant to define some super-type, it should not be declared as abstract
, I'd say.
In your case, I would rather go with a class :
__construct
and __clone
as private methods
Now, why use a Singleton, and not only static methods ? I suppose that, at least a couple of reasons can be valid :
__construct
and __clone
private, and add some getInstance
method.$this
, properties, ...__getStatic
, __setStatic
, ...
This being said, yes, some code like this :
abstract class MyClass {
protected static $data;
public static function setA($a) {
self::$data['a'] = $a;
}
public static function getA() {
return self::$data['a'];
}
}
MyClass::setA(20);
var_dump(MyClass::getA());
Will work... But it doesn't feel quite natural... and this is a very simple example (see what I said earlier with Late Static Binding, and magic methods).