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

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b