What does the PHP error message quot;Notice: Use of undefined constantquot; mean?(PHP 错误信息“注意:使用未定义的常量是什么意思?意思是?)
问题描述
PHP 正在日志中写入此错误:注意:使用未定义的常量".
PHP is writing this error in the logs: "Notice: Use of undefined constant".
日志错误:
相关代码行:
这是什么意思,为什么我会看到它?
What does it mean and why am I seeing it?
推荐答案
你应该引用你的数组键:
You should quote your array keys:
按原样,它正在寻找名为 department
、name
、email
、message
等的常量.当它没有找到这样的常量时,PHP(奇怪地)将其解释为字符串('department' 等).显然,如果您稍后确实定义了这样一个常量,这很容易破坏(尽管使用小写常量是不好的风格).
As is, it was looking for constants called department
, name
, email
, message
, etc. When it doesn't find such a constant, PHP (bizarrely) interprets it as a string ('department', etc). Obviously, this can easily break if you do defined such a constant later (though it's bad style to have lower-case constants).
这篇关于PHP 错误信息“注意:使用未定义的常量"是什么意思?意思是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!