guys! I am practising class extending now but I think I really miss something.
I have some variables first:
$username = "antonradev";
$name = "Anton Radev";
$email = "antonradev@example.com";
$profession = "Designer";
$job_title = "Web Design Manager";
$job_location = "Sofia";
My parent class:
class User {
public $username;
public $name;
public $email;
public function __construct($username, $name, $email) {
$this->username = $username;
$this->name = $name;
$this->email = $email;
}
}
After this I extend like this:
class User_Professional extends User {
public $user_profession;
public $user_job_title;
public $user_work_location;
public function __construct($user_profession, $user_job_title, $user_work_location) {
$this->user_profession = $user_profession;
$this->user_job_title = $user_job_title;
$this->user_work_location = $user_work_location;
}
}
I create an instance:
$user_professional = new User_Professional($username, $name, $email, $profession, $job_title, $job_location);
And I am trying to print some data:
print "The employee username is: " . $user_professional->username;
But nothing happen. Its empty with no errors:
The employee username is:
Then I make some changes and I am trying to print other property:
print "The employee`s job title is: " . $user_professional->user_job_title;
But I get data from the parent class. It prints wrong property:
The employee`s job title is: Anton Radev
Is this normal? Where is my mistake? I cannot handle it. Thank you!