Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does {} mean?

Tags:

php

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();
like image 850
zarcel Avatar asked Nov 30 '12 20:11

zarcel


People also ask

What {} means in math?

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.

What is this called []?

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.

What do curly brackets mean in math?

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}.

What do brackets mean in expressions?

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.


2 Answers

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

like image 69
cryptic ツ Avatar answered Sep 17 '22 23:09

cryptic ツ


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

like image 41
Benjam Avatar answered Sep 20 '22 23:09

Benjam