最新消息:20210917 已从crifan.com换到crifan.org

【已解决】WordPress中php出错:PHP message PHP Warning Use of undefined constant PRC

PHP crifan 884浏览 0评论
折腾:
【未解决】WordPress的php的log文件php-fpm.log太大
期间,去看php的错误日志:
/usr/local/php/var/log/php-fpm.log
PHP message: PHP Warning:  Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/themes/daqianduan-d8-jquiss/comments.php on line 17"
PHP message: PHP Warning:  Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/themes/daqianduan-d8-jquiss/comments.php on line 17"
PHP message: PHP Warning:  Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/themes/daqianduan-d8-jquiss/comments.php on line 17"
PHP message: PHP Warning:  Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/themes/daqianduan-d8-jquiss/comments.php on line 17"
PHP message: PHP Warning:  Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/themes/daqianduan-d8-jquiss/comments.php on line 17"
PHP message: PHP Warning:  Use of undefined constant DESC - assumed 'DESC' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/themes/daqianduan-d8-jquiss/404.php on line 10"
PHP message: PHP Warning:  Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/themes/daqianduan-d8-jquiss/comments.php on line 17"
PHP message: PHP Warning:  Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/themes/daqianduan-d8-jquiss/comments.php on line 17"
PHP message: PHP Warning:  Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048"
PHP message: PHP Warning:  Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/themes/daqianduan-d8-jquiss/comments.php on line 17"
PHP message: PHP Warning:  Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/themes/daqianduan-d8-jquiss/comments.php on line 17"
PHP message: PHP Warning:  Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/themes/daqianduan-d8-jquiss/comments.php on line 17"
PHP message: PHP Warning:  Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048"
...
-》发现php的error的log
主要是
  • themes/daqianduan-d8-jquiss/comments.php
  • themes/daqianduan-d8-jquiss/404.php
  • plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php
这几个地方的错误
PHP message PHP Warning Use of undefined constant PRC  assumed  PRC this will throw an Error in a future version of PHP themes daqianduan-d8-jquiss comments.php on line 17
[修复PHP 7.2 / PHP 7.3] PHP警告:使用未定义的常量(在将来的PHP版本中将引发错误)-隐藏设置
【已解决】python中mysql异常时获取Exception的code – 在路上
解决php7.2后报错Warning: Use of undefined constant PRE – assumed问题_weixin_30273175的博客-CSDN博客
Undefined constant error in php 7.2 – Stack Overflow
$name = "Aniket";
echo name; // forgot to add $ before name
->
$name
使用变量必须加上$前缀
以及:
echo $_POST[email];
-》
* echo $_POST["email"];
去改代码
下去找第一个
wp-content/themes/daqianduan-d8-jquiss/comments.php on line 17
date_default_timezone_set(PRC);
好像是要给PRC加上$?
不过
消除警告Notice: Use of undefined constant PRC-码农场
此处说是:
之后发现提示Notice:  Use of undefined constant PRC – assumed ‘PRC’,原来PHP5.1.0以后date_default_timezone_set被重写,PRC无效了.改成
date_default_timezone_set("Asia/Shanghai");
PHP message PHP Warning Use of undefined constant “PRC”  assumed
解决Yusi1.0主题使用中存在的问题_zhouzying的博客-CSDN博客
https://blog.csdn.net/zhouzying/article/details/82690844
解决方法:修改文件./yusi1.0/comments.php 将date_default_timezone_set(PRC)改为date_default_timezone_set(‘PRC’),参数类型应该为:string
参考:
bool date_default_timezone_set ( string $timezone_identifier );
php date_default_timezone_set
PHP: date_default_timezone_set – Manual
date_default_timezone_set
(PHP 5 >= 5.1.0, PHP 7)
date_default_timezone_set — 设定用于一个脚本中所有日期时间函数的默认时区
说明 ¶
date_default_timezone_set ( string $timezone_identifier ) : bool
date_default_timezone_set() 设定用于所有日期时间函数的默认时区。
Note: 
自 PHP 5.1.0 起(此版本日期时间函数被重写了),如果时区不合法则每个对日期时间函数的调用都会产生一条E_NOTICE 级别的错误信息,如果使用系统设定或 TZ 环境变量则还会产生 E_STRICT 级别的信息。
PHP date_default_timezone_set() 函数
date_default_timezone_set("Asia/Shanghai");

timezone
必需。规定要使用的时区,比如 "UTC" 或 "Europe/Paris"。
所以此处,和
“UTC”
类似的,应该写成:
“PRC”
PHP date_default_timezone_set() Function
php timezone PRC
php.ini中的时区设置date.timezone = PRC – 唔愛吃蘋果 – 博客园
无意中发现 lnmp 默认的 php.ini 配置中有一行 date.timezone = PRC。PRC,People’s Republic of China,中华人民共和国,也就是日期使用中国的时区。
搜索了一下 PHP 源码,在 ext/date/lib/timezonemap.h 中看到如下代码
{ "cst",   0,  28800, "Asia/Chongqing"                },
{ "cst",   0,  28800, "Asia/Chungking"                },
{ "cst",   0,  28800, "Asia/Harbin"                   },
{ "cst",   0,  28800, "Asia/Kashgar"                  },
{ "cst",   0,  28800, "Asia/Macao"                    },
{ "cst",   0,  28800, "Asia/Macau"                    },
{ "cst",   0,  28800, "Asia/Shanghai"                 },
{ "cst",   0,  28800, "Asia/Taipei"                   },
{ "cst",   0,  28800, "Asia/Urumqi"                   },
{ "cst",   0,  28800, "PRC"                           },
{ "cst",   0,  28800, "ROC"                           },
->
所以此处:
"PRC" = People‘s Republic of China = 中华人民共和国 = 日期使用中国的时区
所以可以去改代码了:
date_default_timezone_set("PRC");
结果:
之前错误就消失了。
还有其他的:
PHP message: PHP Warning:  Use of undefined constant DESC - assumed 'DESC' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/themes/daqianduan-d8-jquiss/404.php on line 10"
和:
PHP message: PHP Warning:  Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048"
分别去看看代码
wp-content/themes/daqianduan-d8-jquiss/404.php
            'order'   => DESC,
看看如何处理
PHP message PHP Warning Use of undefined constant “DESC”
PHP message PHP Warning Use of undefined constant DESC
PHP Warning Use of undefined constant ‘DESC’
PHP   constant ‘DESC’
PHP: Predefined Constants – Manual
PHP: constant – Manual
PHP: Constants – Manual
PHP 常量 DESC
PHP 常量 “DESC”
PHP order 常量 “DESC”
PHP MySQL Order By 关键词 | 菜鸟教程
如果你想降序排序,请使用 DESC 关键字。
语法
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC
感觉应该是:
DESC -> 'DESC'
就可以了?
PHP MySQL Order By 关键词
改写为:
'order'   => "DESC",
结果:
真的就没这个错误了。
还剩:
PHP message: PHP Warning:  Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048"
去看看代码
            if ($wp_sh_brush_files[XML][3] == "true" || is_admin()) {
先去找找
wp_sh_brush_files XML
PHP wp_sh_brush_files XML
Ejemplos de código de wp_sh_valid_css en PHP – HotExamples
WP SyntaxHighlighter – WP Hive
没找到有用的。
那估计是,直接改为 XML:
if ($wp_sh_brush_files["XML"][3] == "true" || is_admin()) {
结果:
突然发现,还有更多地方,都是同样语法:
if (is_admin() && $wp_sh_brush_files[XML][3] == "false") {

if (is_admin() && $wp_sh_brush_files[PHP][3] == "false") {

if (is_admin() && $wp_sh_brush_files[XML][3] == "false") {
结果:
不过另外还有:
PHP message: evernote_sync_time()"
然后更新后,只有:
PHP message: evernote_sync_timer()"
PHP message: evernote_sync_schedule 1 step"
PHP message: evernote_sync_time()"
这次,就很少error的log了。
其实可以暂时忽略的。
去看看代码
www.crifan.org/wp-content/plugins/evernote-sync/evernote-sync.php
// 设置定时器
function evernote_sync_timer()
{
    error_log("evernote_sync_timer()");
    if (!wp_next_scheduled('evernote_sync_cron')) {
        error_log("evernote_sync_schedule 1 step");
        wp_schedule_event(time(), 'evernote_sync_time', 'evernote_sync_cron');
    }
}
很是奇怪:为何此处代码,看起来没有逻辑错误,为何非要调用error_log去报错?
那就暂时忽略了。
【总结】
此处php代码报错:
/usr/local/php/var/log/php-fpm.log
PHP message: PHP Warning:  Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.org/wp-content/themes/daqianduan-d8-jquiss/comments.php on line 17"
之类错误,原因是:
应该传入字符串,但是此处传入的都不是字符串,而是无效的宏定义
所以代码从:
www.crifan.org/wp-content/themes/daqianduan-d8-jquiss/comments.php
date_default_timezone_set(PRC);
改为:
date_default_timezone_set("PRC");
即可。
以及后续其他类似错误,也是通用处理方式:
把:
www.crifan.org/wp-content/themes/daqianduan-d8-jquiss/404.php
'order'   => DESC,
改为:
'order'   => "DESC",
把:
www.crifan.org/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php
if ($wp_sh_brush_files[XML][3] == "true" || is_admin()) {
。。。
if (is_admin() && $wp_sh_brush_files[XML][3] == "false") {
。。。
if (is_admin() && $wp_sh_brush_files[PHP][3] == "false") {
。。。
if (is_admin() && $wp_sh_brush_files[XML][3] == "false") {
改为:
if ($wp_sh_brush_files["XML"][3] == "true" || is_admin()) {
。。。
if (is_admin() && $wp_sh_brush_files["XML"][3] == "false") {
。。。
if (is_admin() && $wp_sh_brush_files["PHP"][3] == "false") {
。。。
if (is_admin() && $wp_sh_brush_files["XML"][3] == "false") {
即可。

转载请注明:在路上 » 【已解决】WordPress中php出错:PHP message PHP Warning Use of undefined constant PRC

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
99 queries in 0.194 seconds, using 23.47MB memory