A similar question was asked here: PHP variable like $myvar-test is not valid?
And I've read the PHP Userland Naming Guide Where it says:
Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
What I'm curious about is this answer , and why these workarounds work: ${'0x00'}
, or this: ${'900'}
, or this ${'bad-name'}
.
My question has two parts... why does this work? The second part of my question: Would they be considered valid variables or would be considered something else (I'm not asking if they work, but what they would be classified as.)
According to this link : http://cowburn.info/2008/01/12/php-vars-curly-braces/
the answers are :
$_GLOBALS
array.$var
notation.I believe the parser actually isn't validating the expression inside { }. Althought, internally PHP uses a HashTable to store variables, so any string or number is valid.