Can you assign values to constants with equal sign after using defined in php?

后端 未结 2 541
予麋鹿
予麋鹿 2021-01-18 06:33

I know to define a constant, you do something like this

define(\"CONSTANT\", \"Hello world.\");

if I want to change the value of the consta

相关标签:
2条回答
  • 2021-01-18 06:50

    The whole point of a constant is that it is constantly and always the same. You can not change a constant after you defined it.

    Even using define("CONSTANT", "Hello world."); would return an error.

    I just did it real fast to show you what you'd get:

    Notice: Constant CONSTANT already defined in /Users/stokholm/test.php on line 3
    
    Call Stack:
        0.0003     629992   1. {main}() /Users/stokholm/test.php:0
        0.0171     630232   2. define() /Users/stokholm/test.php:3
    
    0 讨论(0)
  • 2021-01-18 07:10

    Constants, as the name specifies, cannot be changed once defined. Use variables instead.

    0 讨论(0)
提交回复
热议问题