首页 > 解决方案 > 致命错误:无法在 php wordpress 的写入上下文中使用函数返回值

问题描述

致命错误:无法在 /home2/property/teampropertyhunter.com/wp-content/plugins/google-analytics-for-wordpress/lite/includes/admin/wp-site-health.php 的写入上下文中使用函数返回值在第 106 行

public function is_tracking() {

    if ( ! isset( $this->is_tracking ) ) {
        $this->is_tracking = ! empty( monsterinsights_get_ua() );
    }

    return $this->is_tracking;

}

标签: phpwordpress

解决方案


在 php < 5.5 中(感谢@jszobody 指出),您不能像empty()在函数返回时那样运行检查。您可以(至少)两种不同的方式来解决它:

在检查之前将值分配给变量:

if ( ! isset( $this->is_tracking ) ) {
    $monsterUA = monsterinsights_get_ua();
    $this->is_tracking = ! empty( $monsterUA );
}

或者,只使用值和三元运算符的存在:

if ( ! isset( $this->is_tracking ) ) {
    $this->is_tracking = monsterinsights_get_ua() ? TRUE : FALSE;
}

推荐阅读