码修
23 小时前
今天遇到了 PHP 常量未定义的问题:
WordPress - Use of undefined constant REQUEST_URI - assumed 'REQUEST_URI' in functions.PHP on line 73 - Stack Overflow
原因是 php7.2 之后废弃了一些不好的写法, 包括以上错误: 不带引号的字符串 .
不带引号的字符串是不存在的全局常量, 转化成他们自身的字符串.
在以前, 该行为会产生 E_NOTICE, 但现在会产生 E_WARNING. 在下一个 PHP 主版本中, 将抛出 Error 异常.
- <?PHP
- var_dump(NONEXISTENT);
- /* Output:
- Warning: Use of undefined constant NONEXISTENT - assumed 'NONEXISTENT' (this will throw an Error in a future version of PHP) in %s on line %d
- string(11) "NONEXISTENT"
- */
参考资料
PHP: PHP 7.2.x 中废弃的功能 - Manual
What does the PHP error message "Notice: Use of undefined constant" mean? - Stack Overflow
来源: http://www.mzh.ren/php-7-use-of-undefined-constant-error.html