单纯自己做个memo,有相同情况的可以借鉴看看
狂雨1.32版本,PHP7.4,mySQL5.7运行环境,因为框架是thinkphp5.1,所以在PHP5.6下运行是一切正常的,但是在PHP7.4环境下,会出现各种奇奇怪怪的错误。
点击书库出现Trying to access array offset on value of type bool错误
查看application\common\model\Api.php文件
public function get_tpl($id,$tpl_type){ $tpl=$this->get_category($id); if($tpl[$tpl_type]){ return $tpl[$tpl_type]; } if($tpl['pid']==0){ $this->error='模板未设置!'; }else{ return $this->get_tpl($tpl['pid'],$tpl_type); } }
修改if($tpl[$tpl_type]){ 部分
public function get_tpl($id, $tpl_type) { $tpl = $this->get_category($id); if (!is_array($tpl)) { $this->error = '返回的数据结构不正确!'; return null; } if (array_key_exists($tpl_type, $tpl)) { return $tpl[$tpl_type]; } if ($tpl['pid'] == 0) { $this->error = '模板未设置!'; } else { return $this->get_tpl($tpl['pid'], $tpl_type); } }
查看application\home\controller\Lists.php文件
public function lists(){ Cookie::set('__forward__',$this->request->url()); $cid=$this->request->param('id'); $size=$this->request->param('size'); $serialize=$this->request->param('serialize'); $update=$this->request->param('update'); $tag=$this->request->param('tag'); $info=model("common/api")->get_category($cid); $this->view->list_title=empty($info["meta_title"]) ? config("web.meta_title") : $info["meta_title"]; $this->view->list_keywords=empty($info["meta_keywords"]) ? config("web.meta_keyword") : $info["meta_keywords"]; $this->view->list_description=empty($info["meta_description"]) ? config("web.meta_description") : $info["meta_description"]; $tpl=model('common/api')->get_tpl($cid,'template_filter'); if(!$tpl){ $tpl='lists.html'; } $this->assign(['cid'=>$info['id'],'pid'=>$info['pid'],'title'=>$info['title'],'icon'=>$info['icon'],'size'=>$size,'serialize'=>$serialize,'update'=>$update,'tag'=>$tag,'pos'=>1]); return $this->fetch($this->home_tplpath.$tpl); }
修改
$this->assign([‘cid’=>$info[‘id’],’pid’=>$info[‘pid’],’title’=>$info[‘title’],’icon’=>$info[‘icon’],’size’=>$size,’serialize’=>$serialize,’update’=>$update,’tag’=>$tag,’pos’=>1]);部分
public function lists(){ Cookie::set('__forward__',$this->request->url()); $cid = $this->request->param('id'); $size = $this->request->param('size'); $serialize = $this->request->param('serialize'); $update = $this->request->param('update'); $tag = $this->request->param('tag'); $info = model("common/api")->get_category($cid); if (!is_array($info)) { $info = []; } $this->view->list_title = empty($info["meta_title"]) ? config("web.meta_title") : $info["meta_title"]; $this->view->list_keywords = empty($info["meta_keywords"]) ? config("web.meta_keyword") : $info["meta_keywords"]; $this->view->list_description = empty($info["meta_description"]) ? config("web.meta_description") : $info["meta_description"]; $tpl = model('common/api')->get_tpl($cid, 'template_filter'); if (!$tpl) { $tpl = 'lists.html'; } $assignData = [ 'cid' => isset($info['id']) ? $info['id'] : null, 'pid' => isset($info['pid']) ? $info['pid'] : null, 'title' => isset($info['title']) ? $info['title'] : null, 'icon' => isset($info['icon']) ? $info['icon'] : null, 'size' => $size, 'serialize' => $serialize, 'update' => $update, 'tag' => $tag, 'pos' => 1 ]; $this->assign($assignData); return $this->fetch($this->home_tplpath . $tpl); }
修改以上两个文件后,Trying to access array offset on value of type bool错误暂时是解决了,相同运行环境的可以作为借鉴参考