PHP:在定义它时未定义常量

我在PHP中遇到以下错误:

注意:使用未定义的常量常量

在我定义它的确切线上:

define(CONSTANT, true);

我究竟做错了什么? 我定义了它,为什么它会说“Undefined constant”?


你需要引用成为常量的字符串

define('CONSTANT', true);

了解你在做什么错误的最好方法是阅读PHP手册。

这是定义函数的定义

bool define ( string $name , mixed $value [, bool $case_insensitive = false ] )

所以第一个参数必须是一个字符串。


如果你这样写,你正在使用已定义常量的值作为常量名称。

你想要做的是将该名称作为字符串传递:

define('CONSTANT', true);
链接地址: http://www.djcxy.com/p/69257.html

上一篇: PHP: undefined constant while defining it

下一篇: PHP Warning: failed to open stream: No such file or directory, File Path Errors