did you know "you can have cheese burger" could be a variable name?

Well, I didn’t know. But I figured it out while working with SimpleXML to parse an XML document where the node name had a hyphen in it. I was finding a way to refer that element as a SimpleXMLElement and found a nifty note in PHP Manual. It says if you have unsupported (unsupported in PHP Lexicon for a variable name) characters inside the name of a node, you can access it using a special pattern {‘name’}.

So I tried the following code and it show that you can have a class variable named “i can have cheese burger”

$s = new stdClass();
$s->{'i can have cheese burger'} = "Oh Yeaaah";
echo $s->{'i can have cheese burger'}; //it will output "Oh Yeeah"

and if you print_f the object $s, you will see the following

stdClass Object
(
[i can have cheese burger] => Oh Yeeah
)

Well, Its funny! – I love having some fun writing PHP code!