I have use Modx CMS. today i get this error. Bellow my error line.
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
$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
Actually, when i initialize manually $currency
variable 153
then this problem solve. but when i use $currency
initialize from database (int)$product->sm_currency;
it show error
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
For example $currency
variable manually initialize with 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
Now work fine
This could be caused by a change of the PHP version by your hosting company.
Since you added some code in your question: Please check whether an object exist, before you use it (sample below).
$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');
}
}