PHP5 also supports the definiation of object interfaces, which is a way
to ensure that a given class provides a certain set of functions you can
rely on elsewhere:
<?php
class game {
function move_next() {
echo "next";
}
function move_prev() {
echo "prev";
}
}
interface price {
function get_price();
}
class boardgame extends game implements price {
function get_price() {
return 22.95;
}
}
$g = new boardgame;
/* Can we rely on the 'price' interface? */
if($g instanceof price) {
echo "Price is: ".$g->get_price();
}
?>