class Car{
var $wheels=4;
var $doors=4;
function wheelsdoors(){
return $this->wheels + $this->doors;
}
}
class CompactCar extends Car{
var $doors=2;
function wheelsdoors(){
return $this->wheels + $this->doors+ 100;
}
}
$car1 = new Car();
$car2 = new CompactCar();
echo $car1->wheels . "
";
echo $car1->doors . "
";
echo $car1->wheelsdoors() . "
";
echo "
";
echo $car2->wheels . "
";
echo $car2->doors . "
";
echo $car2->wheelsdoors() . "
";
echo "Car parents:".get_parent_class('Car')."
";
echo "CompactCar parents:".get_parent_class('CompactCar')."
";
echo "
";
echo is_subclass_of('Car','Car')? 'true' : 'false';
echo "
";
echo is_subclass_of('CompactCar','Car')? 'true' : 'false';
echo "
";
echo is_subclass_of('Car','CompactCar')? 'true' : 'false';
?>
Source: www.webreference.com
No comments:
Post a Comment