This is the activity in the lesson 3 of Beginning PHP by PacktPub. From what I understand, it should create an instance $markus of the Employee class. The Employee class is a child of BaseEmployee and therefore inherits everything from BaseEmployee. However, if i try to use the method calculateMonthlyPay(), there is a notice and the program does not run correctly. I am using PHP7+ and PHPStorm IDE. here is the notice message and the code:
notice message:
Notice: Undefined property: Employee::$salary in C:\Users\ed.PhpStorm2019.2\config\scratches.\scratch_3.php on line 40 PHP Notice: Undefined property: Employee::$salary in C:\Users\ed.PhpStorm2019.2\config\scratches\scratch_3.php on line 40 Monthly Pay is0 Process finished with exit code 0
the code:
<?php class BaseEmployee { private $name; private $title; private $salary; function __construct($name, $title, $salary){ $this->name = $name; $this->title = $title; $this->salary = $salary; } public function setName($name){ $this->name = $name; } public function setTitle($title){ $this->title = $title; } public function setSalary($salary){ $this->salary = $salary; } public function getName(){ return $this->name; } public function getTitle(){ return $this->title; } public function getSalary(){ return $this->salary; } } class Employee extends BaseEmployee{ public function calculateMonthlyPay(){ return $this->salary / 12; } } $markus = new Employee("Markus Gray", "CEO", 100000); echo "Monthly Pay is" . $markus->calculateMonthlyPay();