From the manual :
Variable names follow the same rules as other labels in PHP. The correct variable name begins with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it is expressed as follows: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
So, if you ran your line through RegEx, you can find out if it is valid or not.
It should be noted that the ability to access the "invalid" names of Object objects using a variable variable is the right approach for some XML parsing.
For example, from SimpleXML docs:
Access to elements in an XML document that contains characters that are not permitted by the PHP naming convention (such as a hyphen) can be achieved by encapsulating the element name in curly braces and an apostrophe.
The following is a sample code:
echo $xml->movie->{'great-lines'}->line;
Therefore, it is not necessary to have properties that can only be accessed in this way.
However, if your code creates and uses an object, you are wondering why you are using these properties. Resolving, of course, a situation similar to the SimpleXML example where an object is created to represent something outside your control.
Tim lytle
source share