interface Greetable {
public function greet(): string;
}
class Person implements Greetable {
}What happens when this code is loaded?
- aNothing, PHP interfaces are optional hints and are ignored at runtime.
- bA fatal error occurs because
Persondoes not implement the requiredgreet()method.✓ - c
Personcompiles fine;greet()is auto-generated with an empty body. - dA warning is printed but the class can still be instantiated normally.
Explanation:A class implementing an interface must define every method the interface declares, or be declared abstract itself. Since
Person implements Greetable without providing greet(), PHP raises a fatal error at class-definition time ("Class Person contains 1 abstract method and must be declared abstract or implement the remaining methods").