This message shows in php 5.4 for some weird reason.
My class looks like this:
abstract class model{
private static
$tableStruct = array();
abstract protected static function tableStruct();
public static function foo(){
if(!isset(self::$tableStruct[get_called_class()]))
self::$tableStruct[get_called_class()] = static::tableStruct();
// I'm using it here!!
}
}
and should be used like:
class page extends model{
protected static function tableStruct(){
return array(
'id' => ...
'title' => ...
);
}
...
}
Why making a static method required by child classes is considered to be against the standards?
Abstract static methods are kind of an odd concept. A static method basically "hard codes" the method to the class, making sure there is only a single instance (~singleton). But making it abstract means you want to force some other class to implement it.
I see what you are trying to do, but when dealing with abstract classes, I would avoid static methods in the base class. What you can do instead is use late static binding (static::) to call a tableStruct method in the "child" class. This doesn't force the the method to be implemented like abstract does, but you could test for the implementation and throw an exception if it doesn't exist.
public static function foo(){
// call the method in the child class
$x = static::tableStruct();
}
For what it's worth...
Abusing interfaces:
interface Imodel {
static function tableStruct();
}
abstract class model implements Imodel {
private static $tableStruct = array();
public static function foo() {
if (!isset(self::$tableStruct[get_called_class()]))
self::$tableStruct[get_called_class()] = static::tableStruct();
// I'm using it here!!
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With