2013-09-29 166 views
1

我有這個函數應該返回一個數組,但它返回NULL。我認爲它可能與它生成的數組大小有關,因爲它有時可以正常工作。我試圖在返回之前做一個var_dump,它總是顯示我需要的數組,但函數輸出的var_dump只顯示NULL。函數應該返回數組,但返回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); 
    } 
} 
+3

除非'Zend_Gdata_App_Exception'被拋出此函數不返回任何內部的功能。 – TheWolf

+0

沒有回報是最後一行?似乎很麻煩.... – FloydThreepwood

+0

是的,我知道。但最終應該拋出異常。儘管如此,我仍會嘗試返回其他地方。 – CupOfTea696

回答

2

你應該返回最後if()聲明

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); 
    } 
} 
+0

你甚至不能放鬆最後的'如果'?否則,你需要另一個回報。 – FloydThreepwood

+0

那麼'catch'會做另一個返回,如果它沒有捕獲'if($ videoFeed)'將會返回 – doitlikejustin

+1

它工作,謝謝你! – CupOfTea696