pbm using parent:: in child class
Posted: Tue Apr 06, 2010 2:21 am
Hi, I have a problem using oop features in php.
I want to use some "employee" class properties and methods in the "payroll" class (child class).
employee.php file:
payroll.php file:
view.php file:
output is :
1 - ID: 4
2 - ID:
I don't understand why the parent::get_employee_id() doesn't work in the "payroll" class?
I want to use some "employee" class properties and methods in the "payroll" class (child class).
employee.php file:
Code: Select all
<?php
class employee extends dbConnect implements IEmployee{
protected $employee_id;
public function set_employee_id($var){
$this->employee_id = $var;
} // set_employee_id($input_var)
public function get_employee_id(){
return $this->employee_id;
} // get_employee_id()
} // class employee extends dbConnect implements IEmployee
?>Code: Select all
<?php
include_once 'employee.php';
class payroll extends employee {
protected $t_income;
public function get_parent_employee_id(){
return parent::get_employee_id();
} // get_parent_employee_id()
} // class payroll extends employee
?>Code: Select all
<?php
include_once 'employee.php';
$Emp = new employee;
include_once 'payroll.php';
$Payroll = new payroll;
$Emp->set_employee_id($_GET['ID']);
print '1 - ID: '.$Emp->get_employee_id().'<br>';
print '2 - ID: '.$Payroll->get_parent_employee_id().'<br>';
?>1 - ID: 4
2 - ID:
I don't understand why the parent::get_employee_id() doesn't work in the "payroll" class?