0

So, there are a lot of similar questions about this, but in the application I can’t get it right... And I’m confused, because it’s working on other functions...

So... the code has a constructor like this...

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

And there is just one function, that doesn’t work properly... and I don’t know what more I can do... I tried some solutions, but they don’t seem to fix the problem...

This is the Stack Overflow question that I’d been checking a lot: PHP Fatal error: Using $this when not in object context

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Excorpion
  • 235
  • 1
  • 12
  • You've probably got PHP5 and you're calling the function statically like `MyClass::TheFunction()`. You can't do that. You have to instantiate an object with `$obj = new MyClass()` and then call the function with `$obj->TheFunction()`. – Alex Howansky Nov 25 '19 at 14:19
  • *"And there is just one function, that doesnt work properly."* - by *"just one function"* do you mean it's a "regular" global function, not part of a class? – CD001 Nov 25 '19 at 14:20
  • @AlexHowansky The php version could affect this??? cause this program is a local copy, and works on the other pcs... and, the code its just that, its not called with "::" – Excorpion Nov 25 '19 at 14:29
  • @CD001 There are a lot of them starting like that, and they work fine... its just 1 of 32 functions... the other 31 works perfectly. – Excorpion Nov 25 '19 at 14:30
  • Calling a non-static function statically became an error in 7, but you're not getting that error, so I presume you're on 5. Post the function that contains the line where the error is. – Alex Howansky Nov 25 '19 at 14:35
  • where is the class for this? you're obviously using OOP. – Funk Forty Niner Nov 25 '19 at 14:36
  • @AlexHowansky currently im using 7.2.18, my coworker is using that too... i paste the complete function so you can check it – Excorpion Nov 25 '19 at 14:42
  • Presuambly its the `$db = $this->db;` portion causing the error. Is this function part of a class? or is it just a single file with this function? From the descriptions so far, it doesn't sound like the function is part of a class. – timswann Nov 25 '19 at 14:50
  • @AlexHowansky You where right, it was the php version... we where using the php7 when the program was code on php5... we tune down the version and the code works fine. (the program was using 5.3, and we were using 7.3 .. we put the 5.6 and its working) – Excorpion Nov 25 '19 at 14:55
  • Please don't use PHP 5. This is irresponsible. Fix your code. Also don't put solved in the question. Use answer space for the solution. – Dharman Nov 25 '19 at 15:12
  • Its not my decision, its not my app :C i just work here... and where is the answer space ?? – Excorpion Nov 25 '19 at 15:24
  • So, i found that the problem was the php version. with you guys, but now im blocked cause the question has a dislike, can u help me ? – Excorpion Nov 13 '20 at 13:52

1 Answers1

1

The answer was checking the PHP version of the program.
The program was created using PHP 5.3, and we were using 7.3.
Using WAMP, we configured the PHP to 5.6 and it works fine.

Thanks to Alex Howansky for putting an eye on the PHP version.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Excorpion
  • 235
  • 1
  • 12