I am attempting to migrate some PHP code from 4.4 to 5.2. I am new to PHP and OOP, but I seem to be doing okay so far. However, there is one particular section of code I am having difficulty with, and web searches have not helped me understand what I need to do here so far. I have copied what I believe are the relevant sections of the code in question below and marked the problem line with //PROBLEM LINE IS HERE. I would be very grateful for any assistance.
class Event {
function Event($clinician,$now) {
global $username;
$this->InDB = '';
$this->NoteID = '';
$this->EntryFor = $clinician;
$this->TimeStamp = $now;
$this->EntryBy = $username;
$this->AtStep = '2';
$this->Location = '';
$this->ChiNumStart = '';
$this->GroupId = '0';
$this->Date = '';
$this->StartTime = '';
$this->EndTime = '';
$this->TravelTime = '0';
$this->PreparationTime = '0';
$this->ParticipationTime = '';
$this->ReviewTime = '0';
$this->ServiceList = array();
$this->ThisClinician = new Clinician();
$this->OtherCliniciansList = array();
$this->MembersList = array();
$this->NonMembersList = array();
$this->CoSignature = '';
$this->NoteType = '';
$this->ProgressNote = new ProgressNote();
$this->IRAP = new IRAP();
$this->PCITNote = new PCIT();
$this->NoteWritingTime = '';
$this->ErrorList = array();
$this->Debug = 0;
}
function loadFromDB($event_id,$clinician) {
require_once("../includes/connect.php");
// PROBLEM LINE IS HERE
$this = new Event($clinician,strtotime('now'));
$event_table = mysql_fetch_object(mysql_query("select * from events where id like '$event_id'"));
$this->InDB = $event_table->id;
$this->TimeStamp = $event_table->entry_date;
$this->Date = $event_table->date;
$this->StartTime = $event_table->start_time;
$this->EndTime = $event_table->end_time;
$this->ChiNumStart = $event_table->chi_num_start;
$this->GroupId = $event_table->group_id;
$this->Location = $event_table->location;
$this->AtStep = $event_table->at_step;
$this->EntryFor = $event_table->entry_for;
$this->CoSignature = $event_table->co_signature;
$this->NoteWritingTime = $event_table->note_writing_time;
$this->NoteType = $event_table->note_type;
$this->NoteID = $event_table->note_id;
$event_services_table = mysql_query("select * from event_services where event_id like '$event_id' and active like '1'");
while($service = mysql_fetch_object($event_services_table)) {
$new_service = new Service($service->service_id,$service->service_title);
$new_service->OverrideCode = $service->override_code;
$this->ServiceList[] = $new_service;
}
$clinician_res = mysql_query("select * from event_clinicians where event_id like '$event_id' and active like '1'");
while($clinician_table = mysql_fetch_object($clinician_res)) {
if(strcmp($clinician_table->clinician_name,$this->EntryFor)) {
$add_clinician = new Clinician();
$add_clinician->Name = $clinician_table->clinician_name;
$add_clinician->ID = $clinician_table->clinician_id;
$add_clinician->Present = $clinician_table->present;
$add_clinician->PreparationTime = $clinician_table->prep_time;
$add_clinician->ParticipationTime = $clinician_table->participation_time;
$add_clinician->ReviewTime = $clinician_table->review_time;
$add_clinician->TravelTime = $clinician_table->travel_time;
$add_clinician->MileageStart = $clinician_table->mileage_start;
$add_clinician->MileageEnd = $clinician_table->mileage_end;
$add_clinician->Authorized = $clinician_table->authorized;
$add_clinician->Role = $clinician_table->role;
$this->OtherCliniciansList[] = $add_clinician;
} else {
$this->PreparationTime = $clinician_table->prep_time;
$this->ParticipationTime = $clinician_table->participation_time;
$this->ReviewTime = $clinician_table->review_time;
$this->TravelTime = $clinician_table->travel_time;
$this->MileageStart = $clinician_table->mileage_start;
$this->MileageEnd = $clinician_table->mileage_end;
}
}
}
}
Is $this = new Event($clinician,strtotime('now')); just calling the class constructor function and can be replaced with $this->Event($clinician,strtotime('now'));? Or does it create a new blank event whenever the function is called in which case maybe I should remove the line and then add a $variablename = new Event ($clinician,strtotime('now')); line before any $variablename->loadFromDB($event_id,$clinician) lines in order to create the new instance before calling the function? Or am I just entirely misunderstanding what the effect of this line is?