Use of undefined constant erorr in php

后端 未结 2 1098
生来不讨喜
生来不讨喜 2021-01-17 07:01

I receive errors(mentioned below code) when I switched my code to another system,

Configurations:

OS : Windows 7 php server : Xampp

Please help me t

相关标签:
2条回答
  • 2021-01-17 07:11

    Your constants need to be strings. So you have to "wrap" them in quotes like this:

    define('ROOT',$_SERVER['DOCUMENT_ROOT']);
           ^    ^
    

    When in doubt, always check the Manual, in that case define()

    Add:
    Also defining constants in a function is, what I find, a bit "dodgy". If you insist on not moving them to another (e.g. config) file which is loaded in the very beginning then at least take them out of the class construct.

    0 讨论(0)
  • 2021-01-17 07:20

    I think you have mis-understood what Define & constants are/do it doesn't really make sense to define a constant in that way from within an Object.

    Perhaps this is a better approach to what you are doing:

    http://php.net/manual/en/language.oop5.constants.php

    Alternatively, the most common usage of setting up items using defines is withing a si9mple setting or config file...

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