A quick example of polymorphing in PHP, is to be commented and better written.
<?php
interface world {
function j($j);
function i($i);
}
class foo implements world {
public function i($i) {
return $i * 2;
}
public function j($j) {
return $j * 3;
}
}
class bar extends foo implements world {
public function j($j) {
return $j * 1;
}
public function __call($name, $args) {
return $name;
}
}
class hello implements world {
function j($j="") {
return "foo";
}
function i($i="") {
return "bar";
}
}
$x = new foo();
$y = new bar();
$z = new hello();
echo "foo: " . $x->i(2) . "<br/>";
echo "foo: " . $x->j(2) . "<br/>";
echo "bar: " . $y->i(2) . "<br/>";
echo "bar: " . $y->j(2) . "<br/>";
echo $z->j(), " ", $z->i();
?>