有没有懂PHP的大神

30次阅读

共计 2235 个字符,预计需要花费 6 分钟才能阅读完成。

wordprees 报错 这咋改 Warning: A non-numeric value encountered in        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);} 复制代码 白日梦 2023-07-13 23:38 2$page = get_query_var(\’cpage\’)-1;$cpp=get_option(\’comments_per_page\’); 复制代码这两个值,或者   get_query_var(\’cpage\’)    的值,不是数字。lastname 2023-07-13 23:53 3The 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:PHPif (!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:PHPfunction 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. lastname 2023-07-13 23:55 4 这个警告信息通常是由于代码中出现了非数字类型的变量参与了数 ** 算,导致 PHP 报出警告。在这个代码段中,可能是以下语句引起了警告:Copy$commentcount = intval($cpp) * intval($page); 建议你可以使用 is_numeric() 函数来判断变量是否为数字类型,然后再进行数 ** 算:Copyif (is_numeric($cpp) && is_numeric($page)) {    $commentcount = intval($cpp) * intval($page);} else {    // 处理非数字类型的情况} 这样就可以避免出现非数字类型参与数 ** 算的情况,从而避免警告信息的产生。lastname 2023-07-13 23:57 5 这个错误信息表明在代码中遇到了一个非数值的值。根据提供的代码,问题可能出现在以下几行中的一行:bashCopy code$page = get_query_var(\’cpage\’)-1; 这行代码中使用了一个减法操作符,而操作数中可能包含非数值的值。为了解决这个问题,你可以在执行减法操作之前先确保操作数是数值类型的。你可以使用 intval() 函数将其转换为整数,如下所示:bashCopy code$page = intval(get_query_var(\’cpage\’)) – 1; 通过使用 intval() 函数,将 get_query_var(\’cpage\’) 的返回值转换为整数,确保操作数是数值类型的,这样就可以避免出现非数值的错误。请记住,在对代码进行修改之前,最好创建备份以防出现意外情况。三个答案,你喜欢哪个???

正文完
 0