【发布时间】:2019-04-11 01:01:10
【问题描述】:
这段代码:
function CheckOrderStartCount($OrderID)
{
global $pdo;
global $layer;
$apiskey = '';
$stmt = $pdo->prepare('SELECT * FROM orders WHERE OrderID = :OrderID');
$stmt->execute(array(
':OrderID' => $OrderID
));
if ($stmt->rowCount() == 1) {
$row = $stmt->fetch();
$start_count = $row['OrderStartCount'];
$ServiceOrderAPI = $layer->GetData('services', 'ServiceOrderAPI', 'ServiceID', $row['OrderServiceID']);
if (empty($row['OrderStartCount']) && !empty($ServiceOrderAPI)) {
$URL = str_replace('[OrderID]', $row['OrderAPIID'], $ServiceOrderAPI);
$URL = str_replace('[apiskey]', $apiskey, $URL);
$return = $layer->SendCurl($URL);
$resp = json_decode($return);
if (isset($resp) && property_exists($resp, 'start_count'))
$start_count = $resp->start_count;
$stmt = $pdo->prepare('UPDATE orders SET OrderStartCount = :OrderStartCount WHERE OrderID = :OrderID');
$stmt->execute(array(
':OrderStartCount' => $start_count,
':OrderID' => $OrderID
));
}
return $start_count;
} else {
return 0;
}
}
public function DeclarePrice($ProductPrice, $ProductDefaultQuantity, $ProductQuantity)
{
$ProductValue = $ProductPrice / $ProductDefaultQuantity;
return $ProductValue * $ProductQuantity;
}
错误“第一个参数必须是对象或第 227 行上现有类的名称”: if (isset($resp) && property_exists($resp, 'start_count'))
如何解决这个问题?
【问题讨论】:
-
那么,$resp 是什么,它是否适合该功能?您应该调试您的代码以找出并研究您正在使用的 API。相关的,如果不是答案:stackoverflow.com/q/14414379/1531971
-
默认情况下
json_decode返回一个对象或对象数组。问题是$resp似乎既不是对象也不是类名,所以它一定是对象数组。对$resp变量执行print_r以查看其内容。
标签: php