dongliming2416 2011-05-13 02:33
浏览 8
已采纳

PHP一般常量

I understand that wanting to update or remove a constant is the exact opposite if what it is meant for, but here is my problem.

I want to be able to format a value in same same fashion that a constant does. i.e.: echo foo;

Where it can just be plain text, instead of echoing a variable like $foo.

It may seem like a silly thing to want to do, but I am hoping to create use out of it. However, if this is not possible, I guess that is that.

PS. I 'would' just define it as a constant, however I want it to be able to update (like re-defining it during a foreach).

  • 写回答

3条回答 默认 最新

  • dongweng9474 2011-05-13 02:41
    关注

    Sort of. The first one must be case-insensitive:

    define("myConstant", "blah", true);
    print myConstant; // blah
    define("myConstant", "xxxx"); // No warning outputted
    print myConstant; // xxxx
    

    But, DON'T DO THIS! The whole point of a constant is that it's constant. Although you seem to sort of recognize this, what is wrong with that extra $ sign, really, versus a much more clear code style?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)