When you inherit an interface, you use the extends keyword just like a class.
interface Child Interface Name extends Parent Interface Name { }
Let's look at the code
<?php interface parentinter { public function auto(); } interface childinter extends parentinter { public function run(); public function stop(); public function turn(); } class Car implements childinter { public function run() { return 'run.'; } public function stop() { return 'stop.'; } public function turn() { return 'turn.'; } } $hello = new Car; echo $hello->run(); ?>
In the code above, the Car class follows the interface childinter.
This is true for childinter's rules, but the childinter interface inherits it
parent interface, and parentinter parent has auto(). So you need to declare method auto() in childinter.
But it did cause an error.
Result of the code above
Result
In the code above, let's see if we add an auto() method to the Car class to see if an error occurs.
<?php interface parentinter { public function auto(); } interface childinter extends parentinter { public function run(); public function stop(); public function turn(); } class Car implements childinter { public function run() { return 'run.'; } public function stop() { return 'stop.'; } public function turn() { return 'turn.'; } public function auto() { return 'auto.'; } } $hello = new Car; echo $hello->auto(); ?>
Result
Thank you for visiting. If you have any inquiry or explanation of mistakes, please use the comments below.
//=$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']?>ALL COMMENTS 0
Sort by