Classese: Inheritance
Posted: Fri May 23, 2003 4:25 pm
Can someone tell me whats wrong, correct what I did with my code.. i'm just trying out playing with classes. I want to know how I can get the second class to call the first ones function and print out the name from
get_name;
mod_edit: added php tags
get_name;
Code: Select all
<?php
class mammal_t
{
function mammal_t()
{
}
function set_name($name)
{
$this->name = $name;
}
function get_name()
{
return $this->name;
}
var $name;
}
class human_t extends mammal_t
{
function human_t()
{
}
function get_name()
{
mammal_t::get_name();
}
}
$human = new human_t();
$mammal = new mammal_t();
$mammal->set_name("smith");
echo $human->get_name();
?>