moneyslow.com

Warning: Use of undefined constant CHARSET - assumed ‘CHARSET’ (this will throw an Error in a future version of PHP)解决办法

开关的0和1代表什么?如何快速记住

开关的0和1代表什么?如何快速记住

php环境配置:

# php -v
PHP 7.4.16 (cli) (built: Jun 24 2021 16:41:14) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

有些程序员力求完美,总想暴露所有的错误并解决,于是设置为 error_reporting(E_ALL);
这种情况下,由于php版本变化引发的warning报错就很平常见到,比如:

Warning: Use of undefined constant CHARSET - assumed 'CHARSET' (this will throw an Error in a future version of PHP) in /usr/local/article.php on line 180

php代码出错的地方:

if(strtolower(CHARSET) == 'utf-8') {

php7.2以上把所有的没有加单引号的值都看成了常量,所以改为:

if(strtolower('CHARSET') == 'utf-8') {

就好了。

Exit mobile version