找回密码
 立即注册
查看: 122|回复: 5

有没有懂php的大神

[复制链接]

0

主题

0

回帖

28

积分

新手上路

积分
28
发表于 2023-7-13 23:10:19 | 显示全部楼层 |阅读模式
wordprees 报错 这咋改
Warning: A non-numeric value encountered in
  1.         function devecomment($comment, $args, $depth) { $GLOBALS['comment'] = $comment;global $commentcount;if(!$commentcount) { $page = get_query_var('cpage')-1;$cpp=get_option('comments_per_page');$commentcount = intval($cpp) * intval($page);}
复制代码








回复

使用道具 举报

0

主题

928

回帖

0

积分

新手上路

积分
0
发表于 2023-7-13 23:12:42 | 显示全部楼层
  1. $page = get_query_var('cpage')-1;$cpp=get_option('comments_per_page');
复制代码

这两个值 ,  或者  get_query_var('cpage')   的值 , 不是数字.
回复 支持 反对

使用道具 举报

0

主题

980

回帖

0

积分

新手上路

积分
0
发表于 2023-7-13 23:18:02 | 显示全部楼层
The warning message "Warning: A non-numeric value encountered in" is caused by the line of code $commentcount = intval($cpp) * intval($page);. The intval() function is used to convert a string to an integer. However, the value of $page may not be an integer. For example, if the user is on the first page of comments, the value of $page will be 0. This will cause the intval() function to fail, and the warning message will be displayed.

To fix this error, you need to check the value of $page before calling the intval() function. If the value of $page is not an integer, you can convert it to an integer using the following code:

PHP
if (!is_numeric($page)) {
  $page = 0;
}
请谨慎使用代码。了解详情
Once you have converted the value of $page to an integer, you can call the intval() function without any errors.

Here is the corrected code:

PHP
function devecomment($comment, $args, $depth) {
  $GLOBALS['comment'] = $comment;
  global $commentcount;
  if (!$commentcount) {
    $page = get_query_var('cpage') - 1;
    if (!is_numeric($page)) {
      $page = 0;
    }
    $cpp = get_option('comments_per_page');
    $commentcount = intval($cpp) * intval($page);
  }
}
请谨慎使用代码。了解详情
This code will now correctly convert the value of $page to an integer, and the warning message will no longer be displayed.
回复 支持 反对

使用道具 举报

0

主题

929

回帖

0

积分

新手上路

积分
0
发表于 2023-7-13 23:26:31 | 显示全部楼层
这个警告信息通常是由于代码中出现了非数字类型的变量参与了数**算,导致 PHP 报出警告。在这个代码段中,可能是以下语句引起了警告:

Copy
$commentcount = intval($cpp) * intval($page);
建议你可以使用 is_numeric() 函数来判断变量是否为数字类型,然后再进行数**算:

Copy
if (is_numeric($cpp) && is_numeric($page)) {
    $commentcount = intval($cpp) * intval($page);
} else {
    // 处理非数字类型的情况
}
这样就可以避免出现非数字类型参与数**算的情况,从而避免警告信息的产生。
回复 支持 反对

使用道具 举报

0

主题

1019

回帖

0

积分

新手上路

积分
0
发表于 2023-7-13 23:28:46 | 显示全部楼层
这个错误信息表明在代码中遇到了一个非数值的值。根据提供的代码,问题可能出现在以下几行中的一行:

bash
Copy code
$page = get_query_var('cpage')-1;
这行代码中使用了一个减法操作符,而操作数中可能包含非数值的值。为了解决这个问题,你可以在执行减法操作之前先确保操作数是数值类型的。你可以使用intval()函数将其转换为整数,如下所示:

bash
Copy code
$page = intval(get_query_var('cpage')) - 1;
通过使用intval()函数,将get_query_var('cpage')的返回值转换为整数,确保操作数是数值类型的,这样就可以避免出现非数值的错误。

请记住,在对代码进行修改之前,最好创建备份以防出现意外情况。



三个答案,你喜欢哪个???
回复 支持 反对

使用道具 举报

0

主题

954

回帖

0

积分

新手上路

积分
0
发表于 2023-7-13 23:38:17 | 显示全部楼层
:lolphp大神指的是ChatGPT吗
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|翻墙党

GMT+8, 2026-9-29 07:46 , Processed in 0.070484 second(s), 29 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表