doupuchao4256 2012-06-15 16:09
浏览 107
已采纳

php变量名称和大括号

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.)

  • 写回答

2条回答 默认 最新

  • dongnuo4594 2012-06-15 16:20
    关注

    According to this link : http://cowburn.info/2008/01/12/php-vars-curly-braces/

    the answers are :

    • question 1: because what is inside the braces will be, more than the name of a variable, a key/value pair within the $_GLOBALS array.
    • question 2: they would be part of the $Globals of your script, but you can't access to them with the regular $var notation.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数
  • ¥15 关于#线性回归#的问题:【统计】回归系数要转化为相关系数才能进行Fisher' Z转化吗(相关搜索:回归模型)
  • ¥100 使用matlab解决含分段变量的优化问题