Well, as in the title, I am having a problem due to those things. The problem is occurring due to line X which is while ($right[count($right)-1]<$row['rgt']) { and this is in a function display_tree from SitePoint’s Tree Traversal.
The function was working well, but I don’t know why it has suddenly started to throwing this fatal error.
I tried using error_reporting(-1); to understand what might be causing the error, and the new error log shows me that I’m getting the PHP Notice multiple time, as if in an unfinished loop, till a point where I am get that Out of memory error.
The weird thing is this was working perfectly till two days ago, since when I am pulling my hairs out to decipher what is causing the problem.
Any way to understand what is causing the problem exactly? or may be some other helpful tips?
Here is the while loop inside it’s condition:
if (count($right)>0) {
$j=0;
while ($right[count($right)-1]<$row['rgt']) {
array_pop($right);
$j++;
}
}
Thanks guys.
For starters, the notice
Undefined offset: -1suggests that array$rightis empty.Edit: In your loop you’re popping
$arraydown to nothing… guaranteed to fail. Need to stop the loop before the array becomes empty.This will solve the immediate problem, but it’s unlikely (by itself) to make your program work:
Since
end($right)returns the same value$right[count($right)-1], we can simplify this to: