PHP Syntax OOP Interfaces

 

- Info:

- This tutorial shows how to declare an interface using keyword .

- Interface defines required functions and constants without specifying exactly how it must be implemented.

- Each class can implement multiple interfaces and for each implementation has to be given:

class airUnit extends plane implements Soldier, Person {}

 

- Example:

- Creat PHP Console Application Test.php.

 

Test.php

<?php

interface Soldier {

CONST MAXAMMO = 100;

function atack($priority);

}

class groundUnit implements Soldier {

function atack($priority) { echo"Attach with rifle"; }

}

class airUnit implements Soldier {

function atack($priority) { echo"Attach with plane"; }

}

?>