-1

I've seen in this answer the code

$tmpNode = parent::addChild($name,null,$namespace);
$tmpNode->{0} = $value;

I'm curious what the ->{0} actually does? Which PHP language construct is this? Does it reference the first property of $tmpNode without using its name?

Update:

I've seen the answers given so far, but I was looking for a reference into the PHP language manual that explains this use of curly braces. When I search in the PHP Manual for curly the only hit is to the page about strings where curly's are only explained in the context of variables and complex expressions. It wasn't clear to me that the language allows curly's around literals.

Community
  • 1
  • 1
Rudiger W.
  • 796
  • 7
  • 13

1 Answers1

1

Curly brackets {} in are also used to parse complex codes. Take this for example:

$t = 0;

$$t = 5;

echo ${0}; //outputs 5

or this:

${0} = 65;

echo ${0}; //outputs 65

but if you were to try this:

$0 = 65;

echo $0;

you would get:

Parse error: syntax error, unexpected '0' (T_LNUMBER), expecting variable (T_VARIABLE) or '$'

It is the same with object properties:

$obj = new stdClass();

$obj->{1} = "Hello world";
echo $obj->{1}; //outputs "Hello world"

Complex (curly) syntax

mega6382
  • 9,211
  • 17
  • 48
  • 69