polymorphism in PHP5

polymorphism in PHP5 sample

class superclass
{
public function
f() { print “superclass-methodn”; }
}

class subclass extends superclass
{
//override
public function f() { print “subclass-methodn”; }
public function
added() { print “subclass-added-methodn”; }
}

function callF( $obj) //superclass
{
$obj->f();
if (
$obj instanceof subclass) $obj->added();
}

callf(new superclass()); //superclass-method
callf(new subclass()); // subclass-method subclass-added-method