FATAL ERROR: Using $this when not in object context, but it works anyway

FATAL ERROR: Using $this when not in object context, but it works anyway

所以,有很多关于这个的类似问题,但是在应用程序中我无法正确... 我很困惑,因为它正在处理其他功能...

所以...代码有这样的构造函数...

public function getMontoDescuentosRealizados($idPropiedad, $idArriendo, $idEstado = 4, $idTipoReceptor = 1)
{
    $db = $this->db;
    $strWhere = ($idArriendo > 0) ? " AND ard.IDArriendoGarantia='" . $idArriendo . "'" : "";
    $query = "SELECT SUM(ardd.MontoCuota) as Descuento
            FROM descuentos_consolidados as ard
            INNER JOIN cuotas_consolidados AS ardd ON (ard.IDConsolidado=ardd.IDConsolidado AND ardd.nCuota=0)
            WHERE ard.Autorizado IN (1)
                AND ard.IDPropiedad=" . $idPropiedad . $strWhere;
    #error_log($query);
    $sql = $db->query($query);
    $row = $sql->fetch_array();
    return ($row["Descuento"] > 0) ? $row["Descuento"] : 0;
}

只有一个功能不能正常工作...我不知道还能做什么...我尝试了一些解决方案,但它们似乎无法解决问题...

这是我一直在检查的 Stack Overflow 问题 很多:PHP Fatal error: Using $this when not in object context

答案是检查程序的 PHP 版本。
该程序是使用 PHP 5.3 创建的,而我们使用的是 7.3。
使用 WAMP,我们将 PHP 配置为 5.6,它工作正常。

感谢 Alex Howansky 关注 PHP 版本。