on-internet
← Community

php - check if class name stored in a string is implementing an interface

Stack Overflow ·

I understand that my question is somehow wrong, but I'm still trying to solve this problem. I have an interface Programmer: interface Programmer { public function writeCode(); } and a couple of namespaced classes: Students\BjarneProgrammer (implements Programmer) Students\CharlieActor (implements Actor) I have this class names stored in array $students = array("BjarneProgrammer", "CharlieActor"); I want to write a function, that will return an instance of class if it's implementing Programmer interface. Examples: getStudentObject($students[0]); - It should return an instance of BjarneProgramme

Comments

Sign in or sign up to comment and upvote.

No comments yet.