I am working on a project where I would like to declare a static member variable inside an abstract base class. I have a Model class, an intermediate Post class, and finally a Post-site class that looks like this:
abstract class Model { protected static $_table = null; protected static $_database = null; ... } abstract class PostModel extends Model { public function __construct() { if ( !isset(self::$_table) ) { self::$_table = 'some_table'; } parent::__construct(); } ... } class SitePostModel extends PostModel { public function __construct() { if ( !isset(self::$_database) ) { self::$_database = 'some_database'; } parent::__construct(); } ... }
I would like to make it obvious from the Model class that the $ _table and $ _database members are required. However, $ _table is really static in terms of the PostModel class, and $ _database is really static in terms of the SitePostModel class.
Is this a legitimate way to achieve my goal? Does the declaration of static variables in the model itself mean that they should exist only once for an abstract base class or only once for a real instance of the class?
source share