试图解构一个函数,我收到一条警告通知,用于从数据库中检索 CSV 数据。
该函数从 index.php 文件中调用,可以格式化为
$masterRecords = $qb->genResultsTable($qid, $config[27]);
$config[27]
是动态设置的,但有助于理解;它是一个以句点分隔的整数列表。eg"3.4.5.6.7.8.9.25.141.137.83"
$qid
是一个整数 - 例如"63"
。
该功能有效,但我想看看我是否可以摆脱 php Notice。
获取通过循环的每个项目的通知:
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]);
}