buildTableName() should convert the class name from "FooRepository" to "foo" but it returns an empty string although the class name is correct when printed in function query(). What's wrong in here?
abstract class Repository
{
protected function buildTableName(): string
{
$shortName = (new \ReflectionClass(self::class))->getShortName();
$tableName = str_replace('Repository', '', $shortName);
return strtolower($tableName);
}
}
class FooRepository extends Repository
{
public function query()
{
echo "my class is ".self::class;
echo $this->buildTableName();
}
}
(new FooRepository())->query();