Example:
<?php interface man { // List of public methods } |
<?php
interface
IMyInterface {
const
INTERFACE_CONST_1 = 1;
const
INTERFACE_CONST_2 =
'a string'
;
public
function
method_1();
public
function
method_2();
}
?>
class
MyClass
implements
IMyInterface {
public
function
method_1() {
// method_1 implementation
}
public
function
method_2() {
// method_2 implementation
}
}
Interesting Points :
interface
Foo {
}
interface
Bar {
}
interface
Bass
extends
Foo, Bar {
}
<?php
// PHP program to Implement interface.
// Define a new Interface for all 'shapes'
// to inherit
interface
Shape {
// Define the methods required for
// classes to implement
public
function
getColor();
public
function
setColor(
$color
);
// Interfaces can't define common
// functions so we'll just define a
// method for all implementations to
// define
public
function
describe();
}
// Define a new 'Triangle' class that
// inherits from the 'Shape' interface
class
Triangle
implements
Shape {
private
$color
= null;
// Define the required methods defined
// in the abstractclass 'Shape'
public
function
getColor() {
return
$this
->color;
}
public
function
setColor(
$color
) {
$this
->color =
$color
;
}
public
function
describe() {
return
sprintf(
"GeeksforGeeks %s %s\n"
,
$this
->getColor(), get_class(
$this
));
}
}
$triangle
=
new
Triangle();
// Set the color
$triangle
->setColor(
'green'
);
// Print out the value of the describe common
// method provided by the abstract class will
// print out out "I am an Orange Triange"
print
$triangle
->describe();
?>