此处提出了类似的问题:PHP variable like $myvar-test is not valid?
我读过 PHP Userland Naming Guide 它说:
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]*'
我很好奇的是这个answer ,以及为什么这些解决方法有效:${'0x00'}
,或者这个:${'900'}
,或者这个${'bad-name' }
。
我的问题分为两部分……为什么这样行得通?我问题的第二部分:它们会被视为有效变量还是会被视为其他变量(我不是问它们是否有效,而是它们将被归类为什么。)
最佳答案
根据此链接:http://cowburn.info/2008/01/12/php-vars-curly-braces/
答案是:
- 问题 1:因为大括号内的内容不仅是变量名,而且是
$_GLOBALS
数组中的键/值对。 - 问题 2:它们将是您脚本的 $Globals 的一部分,但您无法使用常规
$var
符号访问它们。
关于php变量名和大括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11054465/