0

I'm new to php and I'm having some trouble accessing object methods or even object properties after I pull an object from an array. Is this possible? I've done some research and can't seem to find any answers that solve, what feels like to me, a very simple problem.

Here's my static function in a data access class that creates an instructors object with 3 instructor objects:

static function getInstructors()
{
    $instructor1 = new Instructor("123", "Glenn Ray", "test");
    $instructor2 = new Instructor("124", "Rich Mildenberger", "test");
    $instructor3 = new Instructor("125", "Norman", "test");
    $instructorList = new Instructors();
    $instructorList->addInstructor($instructor1);
    $instructorList->addInstructor($instructor2);
    $instructorList->addInstructor($instructor3);
    return $instructorList;
}

Here I'm calling the static function and attempting to loop through the objects in the array and access their public methods:

$instructs = InstructorsDA::getInstructors();
foreach ($instructs->getInstructors() as $i) {
    echo $i->getName();
}

Am I making a simple mistake or is this not possible?

rss428
  • 21
  • 5

0 Answers0