2012-12-04 2 views
1

기능 해체 중 데이터베이스에서 CSV 데이터를 검색하는 데 사용되는 경고 알림이 표시됩니다.PHP : undefined offset in urldecode/explode

기능이의 index.php 파일에서 호출되며,

$masterRecords = $qb->genResultsTable($qid, $config[27]);

$config[27] 동적으로 설정되어 포맷 될 수 있지만, 이해하는 데 도움이; 그것은 정수의 마침표로 구분 된 목록입니다. 예 : "3.4.5.6.7.8.9.25.141.137.83"
$qid은 정수입니다. "63".

이 함수는 작동하지만 PHP 알림을 제거 할 수 있는지 알고 싶습니다.

Notice: Undefined offset: 106 in /vagrant/public/arc/inc/lib.php on line 522 

호출 스택 : 모든 항목에 대한
얻기 사항은 루프를 통과

1 0.0028 417156 {main}() ../index.php:0 
2 1.2886 473280 qb->genResultsTable() ../index.php:66 

기능 : 함자의 대답 @ 만들기 위해

public function genResultsTable($qid, $clist) { 
    $url = "{$this->qb_ssl}{$this->db_id}?act=API_GenResultsTable&ticket={$this->ticket}&apptoken={$this->app_token}&qid={$qid}&clist={$clist}&slist={$clist}&options=csv"; 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cjFile); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, $this->ckfile); 
    // curl_setopt($ch, CURLOPT_HEADER, true); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($ch, CURLOPT_MAXREDIRS, 10); 
    curl_setopt($ch, CURLOPT_COOKIE, "TICKET=" . urlencode($this->ticket)); 
    $r = curl_exec($ch); 
    $r = preg_replace_callback('/([\'"])([^"]+)\1/', 'call_back', $r); 
    preg_match_all('/(.*)\r\n/', $r, $matchs); 
    $fields = explode('.', $clist); 
    $count = count($matchs[0]); 
    $arrs = array(); 
    for ($i = 1; $i < $count; $i++) { 
    $explode_arr = explode(',', $matchs[0][$i]); 
    $arr = array(); 
    foreach ($fields as $key => $field) { 
    // vv THIS BELOW LINE IS THE LINE THAT IS INDICATED IN ERROR vv 
     $arr[$field] = urldecode($explode_arr[$key]); 
    } 
    $arrs[] = $arr; 
    } 
    return $arrs; 
} 

function call_back($matches) { 
    return urlencode($matches[0]); 
} 
+0

함수가 작동하므로 각 행에 $ $ 키가 정의되어 있지 않으며 함수 결과에 아무런 영향을 미치지 않습니다. 'offset undefined'오류가 코드 성능에 영향을 줍니까? – user1874512

+1

항상 이런 종류의 에러를 막기 위해'isset()'을 사용하십시오 ... – HamZa

답변

0

더 명확하고, 기본적으로 당신이 통지를받는 이유는 존재하지 않는 인덱스가있는 배열에 액세스하거나 설정되지 않았습니다 ...

이상적으로 변수 키와 함께 []를 사용할 때마다 키 인덱스/키 해당 배열에 대해 존재합니다.

그래서, 단순히 이것은 잘못된 배열 액세스를 방지하고 통지 멀리 가야

if(isset($arr[$x])){ 
    doSomeThing($arr[$x]) 
} 

doSomeThing($arr[$x]) 앞에 추가.