For anyone wondering, this behaviour works since PHP 5.5
At the time I wrote the question I was maybe lacking of knowledge, instead of trying to assign a value to the static variable if it is empty, simply directly return the value, so it won't be permanently overriden.
abstract class Model {
protected static $table;
static function getTable(){
if(!static::$table){
// ClassName in plural to match to the table Name
return strtolower(static::class . 's');
}
return static::$table;
}
}
class Information extends Model {
static $table = 'infos'; // Overrides ClassName + s
}
class Service extends Model {
}
class Categorie extends Model {
}
print(Service::getTable() . "\n"); // services
print(Information::getTable() . "\n"); // infos
print(Categorie::getTable() . "\n"); // categories