【发布时间】:2021-06-05 09:15:52
【问题描述】:
我在日志文件中收到此错误:
在第 1279 行的 /wp-content/themes/myarcadetheme/functions.php 中遇到的非数字值
这是functions.php中的代码:
function myarcadetheme_game_height( $height ) {
global $post;
if ( ! isset( $post->ID ) ) {
return $height;
}
$width = get_post_meta( $post->ID, 'mabp_width', true );
$ratio = $width / $height;
$new_width = myrcadetheme_game_width( $width );
$height = $new_width / $ratio;
return $height;
}
add_filter( 'myarcade_game_height', 'myarcadetheme_game_height' );
这是在第 1279 行找到的代码。
$ratio = $width / $height;
请帮忙。
【问题讨论】:
-
是错误还是警告?这意味着变量 $width 和 $height 中的一个或两个不是数字。它们可以是存储为文本的数字。它不应该对代码造成任何问题,因为 php 会在除法操作期间将它们转换为数字。 Php 警告在除法操作中使用了文本值,这不是一个好习惯。
-
那么如何修复此错误,使其不会显示在错误日志中。
-
这是一个警告,而不是错误。它对代码没有影响。如果你想避免烦恼,试试这个 $ratio = (int) $width / (int) $height;