I am wondering what { } in the following. What { } is doing here? $this->{$key} = $value;
Thanks in advance.
In one file
$config['field']['calendar'] = array('type'=>'boolean');
$config['field']['category'] = array('type'=>'boolean');
$config['field']['customers'] = array('type'=>'boolean');
...
$this->preference_form->initalize($config);
And in Preference_form.php
function initalize($config = array())
{
foreach($config as $key => $value)
{
$this->{$key} = $value;
}
}
They’re optional in this case, but it’s a way of making it clearer to the reader (and the parser) that you’re referring to a variable.
http://www.php.net/manual/en/language.variables.variable.php
Another case where this syntax is useful is when expanding a function call in a string.
This doesn’t work (or rather it’ll evaluate
$someObjas a string, and then append->someFunc():But this does what you’d expect: