Symfony 7 – PHP – Interfaces

20 multiple-choice questions about PHP interfaces: design, syntax, inheritance, typing, and practical use with small code examples.


Question 1: What problem do interfaces primarily solve in OOP design?

Question 2: Which is TRUE about a class implementing interfaces?

Question 3: Which statement about interface methods is correct?

Question 4: Which is TRUE regarding constants and properties in interfaces?

Question 5: How do interfaces inherit in PHP?

Question 6: What is wrong here? interface Loggable { public function log(string $m); } class FileLogger implements Loggable {}

Question 7: Why is type-hinting against interfaces recommended for dependencies?

Question 8: Which change is allowed when implementing an interface method?

Question 9: What does ($obj instanceof SomeInterface) check?

Question 10: Given interface A { const V = 10; } class C implements A {} echo C::V; What happens?

Question 11: When would you prefer an interface over an abstract class?

Question 12: Is this valid? interface F { public static function from(string $s); } class X implements F { public static function from(string $s) {} }

Question 13: Valid interface method? interface S { public function id(int|string $v): string; }

Question 14: Is this valid? interface I { public int $a; }

Question 15: If two interfaces declare foo with different signatures, what must the implementing class do?

Question 16: Given interface R { public function set(mixed $v): void; } Can a class implement set(int $v): void?

Question 17: How does the Interface Segregation Principle influence interface design?

Question 18: Why is instanceof InterfaceName useful in code using polymorphism?

Question 19: Must parameter names in implementations match those in the interface?

Question 20: Is this valid? interface Repo { public function all(): iterable; } class UserRepo implements Repo { public function all(): array { return []; } }