I've had nearly 15 years experience with scripting languages, but I've never done anything with OOP outside of classwork projects till now.
I'm writing a PHP OOP program that will automate scheduling 1380+ middle school students for the following year. A Counselor object creates Student objects from a MySQL database. After all the Student objects are created, each Student traipses out to bond with a grade level Team (6th, 7th, 8th). The Team Class will assign the student his core courses--Language Arts, Math, Science, and Social Studies--then turn him back over to the Counselor for assignment to Reading and Exploratory classes.
As I said, the student objects are created dynamically from MySQL using an eval() statement. Since these objects aren't hardwired into the code, I have the problem of referencing them individually. NogDog in the PHP 5 forum helped me solve this problem by putting the students into an array.
[CODE]public function addStudent($obj)
{
if(is_a($obj, 'Student'))
{
$this->students[] = $obj;
return(TRUE);
}
else
{
// throw exception or raise error, then:
return(FALSE);
}
}
[/CODE]
However, when I try and reference $students[101], for instance, it does not appear to be a Student object. I wrote the block below to test whether I was getting objects. ($rn will be replaced with a random number in future tests, then with a loop index at the final stage.)
[CODE]$rn = 101;
$whichStudent = $counselor->getStudent($rn);
if (is_a($whichStudent, "Student")) {
echo "Student object returned\n";
$currentStudent = $whichStudent->getStudentFirst()." ".$whichStudent->getStudentLast();
echo $currentStudent." Accessed\n\n";
} else {
echo $whichStudent.": not an object\n\n";
}
[/CODE]
Everything comes off as " : not an object"
Here's the Counselor class method that should return a student object.
[CODE]public function getStudent($n)
{
return $students[$n];
}
[/CODE]
Any suggestions?