1

I have this function that should return an array, but it returns NULL instead. I think it might have to do with the size of the array it generates, because sometimes it does work properly. I have tried to do a var_dump before the return, which always showed the array I needed, however a var_dump of the output of the function just shows NULL.

function getAllUploads($videoFeed, $videos = array(), $counter = 1){
    foreach($videoFeed as $videoEntry){
        if($videoEntry->extensionElements[6]->extensionAttributes['permission']['value'] == "allowed"){
            $videos[] = array("videoID" => $videoEntry->getVideoId(), "uploaded" => ytToMySQLDateTime($videoEntry->getPublished()->getText())); //date('Y-m-d H:i:s', $videoEntry->getPublished()->getText())
        }
        $counter++;
    }

    try{
        $videoFeed = $videoFeed->getNextFeed();
    }catch(Zend_Gdata_App_Exception $e){
        return $videos;
    }

    if($videoFeed){
        getAllUploads($videoFeed, $videos, $counter);
    }
}
CupOfTea696
  • 1,266
  • 3
  • 14
  • 29

1 Answers1

2

You should return the function inside the last if() statement

function getAllUploads($videoFeed, $videos = array(), $counter = 1){
    foreach($videoFeed as $videoEntry){
        if($videoEntry->extensionElements[6]->extensionAttributes['permission']['value'] == "allowed"){
            $videos[] = array("videoID" => $videoEntry->getVideoId(), "uploaded" => ytToMySQLDateTime($videoEntry->getPublished()->getText())); //date('Y-m-d H:i:s', $videoEntry->getPublished()->getText())
        }
        $counter++;
    }

    try{
        $videoFeed = $videoFeed->getNextFeed();
    }catch(Zend_Gdata_App_Exception $e){
        return $videos;
    }

    if($videoFeed){
        return getAllUploads($videoFeed, $videos, $counter);
    }
}
doitlikejustin
  • 6,293
  • 2
  • 40
  • 68