致命错误:无法在PHP Wordpress的写入上下文中使用函数返回值

时间:2019-09-12 03:23:59

标签: php wordpress

  

致命错误:无法在/home2/property/teampropertyhunter.com/wp-content/plugins/google-analytics-for-wordpress/lite/includes/admin/wp-site-第106行的health.php

public function is_tracking() {

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

    return $this->is_tracking;

}

1 个答案:

答案 0 :(得分:0)

在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;
}