This is Employee.class.php
class Employee
{
public $first_name;
public $last_name;
public $date_of_birth;
public function __construct($fn, $ln, $dob)
{
$this->first_name = $fn;
$this->last_name = $ln;
$this->date_of_birth = $dob;
}
public function registerEmployee()
{
require '../config.php';
$stmt = $dbh->prepare("INSERT INTO emp_reg(e_name,
e_lname,
e_dob) VALUES(?,?,?)");
$stmt->execute(array($this->first_name,
$this->last_name,
$this->date_of_birth));
echo "Saved Successfully";
}
public function return_employee_data($employee_id)
{
require '../config.php';
$stmt = $dbh->query("SELECT * FROM emp_reg WHERE e_id = '$employee_id'");
$arr = $stmt->fetchall(PDO::FETCH_ASSOC);
$res = json_encode($arr);
echo $res;
}
}
When I'm going to require this class in some other file say xyz.php
just to
return_employee_data($employee_id);
I've to create an object in that file like
// constructor overloading is not possible so I can't create `$EmployeeObject` like this.
$EmployeeObject = new Employee();
so I can't run this function return_employee_data($employee_name);
like this
$EmployeeObject->return_employee_data($employee_name); //not possible in this new file
If constructor overloading is not possible then how can I create objects with given parameters, and without any parameter? I'd also like to create objects with variable parameters in other files where we have included class definitions only, and the file data either provides no data or variable data to create an object of such definition as above?
If we cannot create an object how can I call its underlying functions for solving any specific problem?