Hey I’m rather new at PHP and I’m getting this error : Call to a member function getTutorial() on a non-object in actionScheduleValidation
This picture shows the error I get.
here’s the call( i was going to put the picture but here’s the code)
Here’s the call that is creating an error → echo $errorArr[$i]->getTutorial()->getSectionID(); It’s weird because the function verification ( which is a bit lower in the code) invokes getTutorial() perfectly fine on Courses object ( which this array is shown to be in the picture above!)
if ($errorArr != null) {
echo "before error";
for($i=0; $i<count($errorArr); $i++){
for($m=0; $m<count($errorArr[$i]); $m++) {
var_dump($errorArr[$i]);
echo $errorArr[$i]->getTutorial()->getSectionID();
}
}
var_dump($errorArr);
echo 0;
$sectionID = array();
/*for($i = 0; $i<count($errorArr)){
for($m=0; $m < count($errorArr[]); $m++){
$sectionID[$m] = $errorArr[$i][$m]->getTutorial() -> getSectionID();
}
}*/
echo json_encode($errorArr);
} else {
echo 1;
}
} else
echo 2;
}
function verification(&$arrayOfSemester){
$errorArr = [];
for($key = 0 ; $key <count($arrayOfSemester)- 1; $key++){
$startLecTimeAtKey = $arrayOfSemester[$key]->getLecture() -> getStartTime();
echo $startLecTimeAtKey;
$endLecTimeAtKey = $arrayOfSemester[$key]->getLecture()->getEndTime();
$startTutTimeAtKey = $arrayOfSemester[$key] -> getTutorial()->getStartTime();
echo $startTutTimeAtKey;
$endTutTimeAtKey = $arrayOfSemester[$key] -> getTutorial() -> getEndTime();
$dayOfLec = $arrayOfSemester[$key] ->getLecture() -> getDays();
$dayOfTut = $arrayOfSemester[$key] ->getTutorial() -> getDays();
$daySofLec = array();
if(strlen($dayOfLec) >= 2){
$daySofLec = str_split($dayOfLec);
}
However, as you can see getTutorial is called in verification with no issues. Now, I know that my coding is a bit everywhere and heavy in terms of lines. However, as seen above, when using var_dump on $errorArr[$i] I get 2 outputs. At index 1 I get an object of type Course that contains both tutorial and lecture. Here’s the class course:
class Courses
{
private $lecture;
private $tutorial;
public function __construct(Lecture $lec, TutorialAndLab $tutorial){
$this->lecture = $lec;
$this->tutorial = $tutorial;
}
/**
* @return mixed
*/
public function getLecture()
{
return $this->lecture;
}
/**
* @param mixed $lecture
*/
public function setLecture($lecture)
{
$this->lecture = $lecture;
}
/**
* @return mixed
*/
public function getTutorial()
{
return $this->tutorial;
}
/**
* @param mixed $tutorial
*/
public function setTutorial($tutorial)
{
$this->tutorial = $tutorial;
}
shouldn’t getTutorial works in my case above? I just can’t seem to find the error. I can also post the code straight up if need be!