How does a PHP class implement an interface?
- implements
- extends
- uses
- inherits
In PHP, a class implements an interface using the implements keyword followed by the name of the interface or a comma-separated list of interface names. For example: class ClassName implements InterfaceName { } By implementing an interface, a class agrees to fulfill the contract defined by the interface. The class must provide an implementation for all the methods defined in the interface. A class can implement multiple interfaces by listing them after the implements keyword. This allows the class to define behavior and functionality according to multiple contracts. To know more about interface implementation, visit: http://php.net/manual/en/language.oop5.interfaces.php
Loading...
Related Quiz
- What is the operator used for addition in PHP?
- In a PHP switch statement, what does the case keyword represent?
- What are some differences between the include and require statements in PHP?
- Explain the concept of dependency injection in PHP. How does it promote loose coupling and better testability?
- You are writing a PHP script and you need to check if a variable contains a numeric value. How would you do this?