You have an infinite loop/infinite recursion going on here.
foreach($array as $key => $project)
{
if($project->getSlug() == $slug) {
return $this->getNextProject($array, $slug, $key + 1);
}
// ...
}
If there are any $array elements that match the condition $project->getSlug() == $slug, it will call getNextProject() again, which will run this foreach again thus calling getNextProject() again... and so on.
You need to reorder/re-think your logic here. You can try to move the if($next != 999) { to the top of the foreach.
Try this:
protected function getNextProject($array, $slug, $next = 999)
{
foreach($array as $key => $project)
{
if($next != 999 && $next == $key) {
return $project->getSlug();
}
if($project->getSlug() == $slug) {
return $this->getNextProject($array, $slug, $key + 1);
}
}
}
Or better yet, you can just do this with one loop and no recursion:
protected function getNextProject($array, $slug)
{
foreach($array as $key => $project)
{
if($project->getSlug() == $slug && isset($array[$key+1])){
return $array[$key+1]->getSlug();
}
}
}
Just find the 1st element that matches the $slug, then get the next one and return its slug.