【发布时间】:2017-03-11 12:23:00
【问题描述】:
注意:尝试在第 354 行的 /home/....................../modules/webox/webox.php 中获取非对象的属性
注意:尝试在第 393 行的 /home/......................./webox/webox.php 中获取非对象的属性
警告:在第 393 行的 /home/......................./webox/webox.php 中为 foreach() 提供了无效参数
代码:346-414
346 类 WeboxClass{
347 公共 $total_count = 0;
public $json;
public function __construct($json = "") {
if(strlen($json) == 0){
$json = $this->downloadAutomatakAndReturn();
}
$this->json = json_decode($json);
354 $this->total_count = $this->json->total_count;}
public function downloadAutomatakAndReturn(){
$tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : (is_callable('sys_get_temp_dir') ? sys_get_temp_dir() : '');
if (!is_file($tmp_dir.'/validboltlista.json') || filemtime($tmp_dir.'/validboltlista.json')+86400<time()) {
$jsonData=file_get_contents('https://api-hu.easypack24.net/v4/machines?type=0');
file_put_contents($tmp_dir.'/validboltlista.json', $jsonData, LOCK_EX);
}else{
$jsonData=file_get_contents($tmp_dir.'/validboltlista.json');
}
return $jsonData;
}
function getAllAutomataAsOptions($selectedAutomata){
$result = "";
$automatak = array();
foreach($this->getAutomatakByTelepules("") as $automata){
/* @var $automata WeboxItem */
$cim = $automata->getAddress_city() . " " . $automata->getAddress_post_code() . ", " . $automata->getAddress_street() . " " . $automata->getAddress_building_no();
$automatak[$automata->getId()] = array(
'text' => $cim . " (" . $automata->getId() . ")",
'id' => $automata->getId(),
'map' => $automata->getMinimap(),
'info' => $automata->getLocation_description()
);
}
sort($automatak);
foreach($automatak as $s){
$selected = (strlen($selectedAutomata) > 1 && $s['id'] == $selectedAutomata ? "selected='selected'" : "");
$result .= "<option value='".$s['id']."' data-map='".$s['map']."' data-info='".$s['info']."' ".$selected.">".$s['text']."</option>\n";
}
return $result;
}
function getAutomatakByTelepules($telepules){
$result = array();
393 foreach($this->json->_embedded->machines as $id => $json){
if($json->address->city == $telepules || strlen($telepules) == 0){
$result[$id] = new WeboxItem($json);
}
}
return $result;
}
function getAutomataByID($id){
foreach($this->json->_embedded->machines as $id => $json){
if($json->id == $id){
return @new WeboxItem($json);
}
}
return null;
}
function getTotalCount() {
return $this->total_count;
}
}
【问题讨论】:
-
您有问题吗?
-
对不起,我有一个问题:解决方案是什么?网页前端debub通知: 注意: Trying to get property of non-object in /home/....................../modules/webox/webox.php在第 354 行注意:尝试在第 393 行的 /home/......................./webox/webox.php 中获取非对象的属性警告: 在第 393 行的 /home/......................./webox/webox.php 中为 foreach() 提供的参数无效