I was reading source of OpenCart and I ran into such expression below. Could someone explain it to me:
$quote = $this->{'model_shipping_' . $result['code']}->getQuote($shipping_address);
In the statement, there is a weird code part that is
$this->{'model_shipping_' . $result['code']}
which has {} and I wonder what that is? It looks an object to me but I am not really sure.
Curly braces are used to denote string or variable interpolation in PHP. It allows you to create ‘variable functions’, which can allow you to call a function without explicitly knowing what it actually is.
Using this, you can create a property on an object almost like you would an array:
Or you can call one of a set of methods, if you have some sort of REST API class:
It’s also used in strings to more easily identify interpolation, if you want to:
Of course these are simplifications. The purpose of your example code is to run one of a number of functions depending on the value of
$result['code'].