Strict standards: The static function model :: tableStruct () should not be abstract in

This message is displayed in php 5.4 for some strange reason.

My class is as follows:

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 as:

 class page extends model{ protected static function tableStruct(){ return array( 'id' => ... 'title' => ... ); } ... } 

Why is the static method required by child classes considered incompatible with standards?

+6
source share
2 answers

Abstract static methods are an odd concept. The static method basically “hardcodes” the method for the class, making sure that there is only one instance (~ singleton). But to make it abstract means that you want to force another class to implement it.

I see what you are trying to do, but when you do abstract classes, I would avoid static methods in the base class. Instead, you can use late static binding (static: :) to call the tableStruct method in the "child" class. This does not cause the method to be implemented as abstract, but you can test the implementation and throw an exception if it does not exist.

 public static function foo(){ // call the method in the child class $x = static::tableStruct(); } 
+7
source

What is it worth ...

Interface violation:

 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!! } } 
+3
source

All Articles