Print_r() and at sign (@)
how can I access property with at sign (@) - @order, in this case? Here is the output of print_r function:
[0] => stdClass Object
(
[@order] => 0
[name] => Arthotel Munich
[address1] => Paul-Heyse-Strasse 10
[city] => Munich
[postalCode] => 开发者_如何学编程80336
[countryCode] => DE
[airportCode] => MUC
)
I have tried $object->@order, $object[@order], $object::order. None of them worked.
Can do
echo $object->{'@order'};
or with a variable variable
$name = '@foo';
echo $object->$name;
But like Tomalak pointed out, you want to change that property name. It leads to fubar code.
The rules for object properties are like the rules for any other variable name.
Thus, a property named @order
is not legal. Call it something else that doesn't have crazy symbols in.
It is possible to get into this situation by converting an array to an object through casting.
精彩评论