【发布时间】:2017-11-01 10:13:08
【问题描述】:
我最近在我的服务器上将我的 PHP 版本从 7.0 更改为 7.1。在查看我的错误日志时,我现在收到以下错误:
AH01071:得到错误“PHP 消息:PHP 警告:在 /width.php 第 74 行遇到的非数字值\nPHP
受影响的代码如下。第 74 行是代码的最后一行,如下所示。
//
// Get settings.
//
$a = x_get_option( 'x_layout_site' );
$b = x_get_option( 'x_layout_content' );
$c = x_get_option( 'x_layout_site_width' );
$d = x_get_option( 'x_layout_site_max_width' );
$e = x_get_option( 'x_layout_content_width' );
$f = x_get_option( 'x_layout_sidebar_width' );
//
// Adjust settings.
//
$site_layout = ( $a == '' ) ? 'full-width' : $a;
$content_layout = ( $b == '' ) ? 'content-sidebar' : $b;
$site_width = ( $c == '' ) ? 88 / 100 : $c / 100;
$site_max_width = ( $d == '' ) ? 1200 : $d;
$content_width = ( $e == '' ) ? 72 - $m : $e - $m; // Line affected
我在下面的地方读到过关于非格式正确的数值遇到的错误。1,2,3,4 做了一些谷歌搜索,似乎这与PHP 7.1 处理非数字计算的方式,如此处所引用。5 建议在 $content-width 中捕获潜在的“自动”值并将其转换为零。我尝试通过以下代码更改来进行此类错误捕获:
//
// Adjust settings.
//
$site_layout = ( $a == '' ) ? 'full-width' : $a;
$content_layout = ( $b == '' ) ? 'content-sidebar' : $b;
$site_width = ( $c == '' ) ? 88 / 100 : $c / 100;
$site_max_width = ( $d == '' ) ? 1200 : $d;
if ($m=='auto') {$m=0;} // set auto to 0
$content_width = ( $e == '' ) ? 72 - $m : $e - $m; // Line affected
但是,错误似乎仍在继续。提出的另一个建议是禁止 PHP 警告,但由于我正在调试其他代码,我不想这样做。我也不认为这是一个好的做法。
对于任何对较大代码体的来源感兴趣的人,它是 WordPress 的“X”主题。仅在从 PHP 7.0 转换到 7.1 时出现此错误。
感谢您对解决此问题的任何见解。谢谢。
【问题讨论】:
-
我有完全相同的错误。你解决了这个问题吗?
标签: error-handling wordpress-theming