簡體   English   中英

自己調用函數時出錯,VCS說=“未定義的函數”

[英]Error when calling function it self, VCS say="undifined function"

我從這里的一個問題中得到了這個功能。 當我嘗試使用單獨的文件時,它會正常運行。 但是當我在一個包含更多函數的類中重寫它時,我寧願在另一個文件中調用它,這個函數中包含的 searchRec(調用函數本身)變成紅色或被 Visual Studio 代碼標記為錯誤。 而之前,在這個函數上面我也寫了同一個函數,其中有一個函數調用本身,它運行正常。

public function searchRec($haystack, $needle, $pathId=Array(), $pathIndex=Array())
{
    foreach($haystack as $index => $item) {

        $pathId[] = $item['Id'];

        $pathIndex[] = $index;

        if($item['Title'] == $needle) {

            $returnObject = new stdClass();

            $returnObject->match = $item;   

            $returnObject->pathId = $pathId; 
            item directly
                $returnObject->pathIndex = $pathIndex; 
            return $returnObject;
        }

        if(isset($item['Children']) && count($item['Children']>0)) {
            (recursively) 

                $result = searchRec($item['Children'], $needle, $pathId, $pathIndex); //searchRec error, VCS say: undifined function

            if($result) {

                return $result;
            }
        }
    }
    return false;
}

由於它是一個類方法,因此您需要使用面向對象的語法來調用它。

$result = $this->searchRec($item['Children'], $needle, $pathId, $pathIndex);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM