I have a class called Report. I have several classes that inherit from report, ClientReport, ClientVisitReport...
class Report {
...
public function load($id) {
...
}
}
class ClientReport extends Report {
...
public function load($id) {
parent::load($id);
...
}
}
class ClientVisitReport extends Report {
...
public function load($id) {
parent::load($id);
...
}
}
I want to be able to call the proper constructor from the id I give to the load method. Each id has its own class of report.
Basically I'm asking how I could do this :
$reportObject = new Report(); // reportObject is a Report
$reportObject->load(15678); // report 15678 is a ClientReport, $reportObject is now a ClientReport
How do I do that ? I may be wrong in my design, is there a better way to do what I want ?