I found this in code, what does it mean and whats the difference between that and normal $dir variable?
global ${$dir};
$this->{$dir} = new $class();
Braces { } are used to identify the elements of a set. For example, {a,b,c} denotes a set of three elements a, b and c.
Parentheses are a pair of punctuation marks that are most often used to add additional nonessential information or an aside to a sentence. Parentheses resemble two curved vertical lines: ( ). A single one of these punctuation marks is called a parenthesis.
In mathematics, curly brackets are used to denote a set. For example, a set containing the numbers 2, 4, 6, 8, and 10 would be written like this: {2, 4, 6, 8, 10}.
Lesson Summary. Brackets, in math, are a set of marks like parentheses that are used to enclose a set of terms. These terms may be within an algebraic expression, and in this case, the brackets are used to separate terms and denote the order of operations.
Its called complex curly syntax.
Any scalar variable, array element or object property with a string representation can be included via this syntax. Simply write the expression the same way as it would appear outside the string, and then wrap it in { and }. Since { can not be escaped, this syntax will only be recognized when the $ immediately follows the {. Use {\$ to get a literal {$.
More info:
http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex
It is taking the value of the $dir
variable and finding the variable with that name.
So if $dir = 'foo';
, then ${$dir}
is the same as $foo
.
Likewise, if $dir = 'foo';
, then $this->{$dir}
is the same as $this->foo
.
http://www.php.net/manual/en/language.variables.variable.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With