我使用的是Modx CMS。今天我收到这个错误。 Bellow我的错误行。
致命错误:在第24行的/var/www/bottega/core/cache/includes/elements/modsnippet/63.include.cache.php中调用null上的成员函数get()
$id = $row['id'];
$product = $modx->getObject('modResource', $id)->Product;
$price = $product->sm_price;
$currency = (int)$product->sm_currency; //$currency out is 153 dynamically
$currency = $modx->getObject('modResource', trim($currency))->get('longtitle'); //this line number 24
实际上,当我手动初始化$currency
变量153
时,此问题就解决了。但是当我使用$currency
初始化数据库(int)$product->sm_currency;
时,它会显示错误
Fatal error: Call to a member function get() on null in /var/www/bottega/core/cache/includes/elements/modsnippet/63.include.cache.php on line 24
例如$currency
变量用153手动初始化
$id = $row['id'];
$product = $modx->getObject('modResource', $id)->Product;
$price = $product->sm_price;
$currency = 153;
$currency = $modx->getObject('modResource', trim($currency))->get('longtitle'); //this line number 24
现在工作正常
答案 0 :(得分:1)
这可能是由托管公司更改PHP版本引起的。
由于您在问题中添加了一些代码:请在使用之前检查对象是否存在(下面的示例)。
$id = $row['id'];
$productRes = $modx->getObject('modResource', $id);
if ($productRes && $productRes->Product) {
$product = $productRes->Product;
$price = $product->sm_price;
$currency = (int)$product->sm_currency;
$currencyRes = $modx->getObject('modResource', $currency);
if ($currencyRes) {
$currency = currencyRes->get('longtitle');
}
}