I found out that due to inheritance static properties are shared in sibling classes even when called in static context instead of self
abstract class Repository {
protected static ?string $tableName = NULL;
protected static getTableName(): string {
if(static::$tableName){
return static::$tableName;
}
$tableName = "";
// business logic
static::$tableName = $tableName;
}
}
final class UserRepository extends Repository {
}
final class CompanyRepository extends Repository {
}
So if UserRepository::getTableName is called, even CompanyRepository::tableName is set to "user" eg, so that the if(static::$tableName){ will be TRUE in CompanyRepository context and CompanyRepository::getTableName will return "user" as well.
In order to overcome this behaviour there are two solutions:
Solution #1
Where the code in abstract
Repositoryworks as isSolution #2
Leave the inherited classes as is while change the abstract class as: