【问题标题】:Fatal error: Can't use function return value in write context on php wordpress致命错误:无法在 php wordpress 的写入上下文中使用函数返回值
【发布时间】:2019-09-12 03:23:59
【问题描述】:

致命错误:无法在 /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;

}

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

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

    【讨论】:

    • 您可以从 php 5.5 开始。文档说 5.5.0 “empty() 现在支持表达式,而不仅仅是变量。”听起来 OP 正在运行 php 5.4 或更早版本。
    • @jszobody 我想我的年龄正在显示,哈哈。我被empty() 问题咬了几次,然后就再也没有那样用过!
    • 是的,我假设这段代码是 WP 插件的一部分,而不是 OP 自己编写的。插件作者可能并不打算支持真正的 php 版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-12
    • 2015-07-03
    相关资源
    最近更新 更多