I have inherited some code like this
public static function instanciateRepository( $repositoryClass, ... ) {
...
new $repositoryClass( ... );
}
Where $repositoryClass
is a class type that needs to be instanciated.
I want to add a syntax check for passing a wrong class argument to this function, specifically limit $repositoryClass
to sublasses of CommonRepository
.
Is there a syntax construction to achieve that in PHP, e.g. instanciateRepository( CommonRepository::class $repositoryClass, ..
?