I have a doubt regarding to inheritance and calling a parent method from an extended class: The code is:
Code: Select all
<?php
class person {
var $name;
function __construct($persons_name){
$this->name = "Person".$persons_name;
}
function set_name($new_name){
$this->name = "Person".$new_name;
}
function get_name(){
return $this->name;
}
}
class employee extends person {
function __construct($persons_name){
$this->name = "Employee".$persons_name;
}
function set_name($new_name){
$this->name = "Employee".$new_name;
}
function get_name(){
parent::get_name();
}
}
?>Code: Select all
$employed_man = new employee("Man Employed");
echo $employed_man->get_name();Shouldn't this work? I tried to make an echo "testing"; inside get_name, and it does the echo, so I supposed is related with the $this variable, but I am not sure.
Some help?
Appreciate