I am facing an issue with $this in a code of extension. Looks like PHP version issue. In one server all working fine and in another server it is not working & giving error like this :-

Fatal error: Uncaught Error: Using $this when not in object context in filename.php on line no. 12

The code on line no.12 is :

if (!$this->getConditions())
    return true;

If I comment this code then error comes on another line where there is $this.

The server where everything is working fine, it's PHP version is : 5.3 The server where error is coming, it's PHP version is : 7.0

I guess this PHP version may be the issue but can anyone please tell the solution for this? or there is no way except changing the PHP version?

EDIT: scope:

class Namespace_Module_Model_SalesRule_Rule_Condition_Product_Comb‌​ine 
    extends Mage_SalesRule_Model_Rule_Condition_Product_Combine
    public function validate(Varien_Object $object)
        if (!$this->getConditions()) {
            return true;

        // ..... other code....

  • Is the scope of the code a static method by chance? Commented Sep 5, 2017 at 10:59
  • no not a static method. Here is the class & main function :- class Namespace_Module_Model_SalesRule_Rule_Condition_Product_Combine extends Mage_SalesRule_Model_Rule_Condition_Product_Combine { public function validate(Varien_Object $object) { if (!$this->getConditions()) { return true; } .....other code.... } } Any idea?
    – KA9
    Commented Sep 5, 2017 at 11:15
  • Are you calling the method as being static from somewhere else? Commented Sep 5, 2017 at 12:00
  • Hi Giel, first of all thank you for your interest in solving this for us but the thing is wherever $this comes, error comes there except that we do not know any thing. We know only that no error coming in one server & in another server the above given error comes :(
    – KA9
    Commented Sep 5, 2017 at 12:20

1 Answer 1


We came across the same issue while working a client's site. The problem for us was that the method was being called statically

Here's the snippet we updated

$valid = Mage_Rule_Model_Condition_Combine::validate($object);


$combiner = Mage::getModel('rule/condition_combine');
$valid = $combiner->validate($object);

Note: For our use case, we directly instantiated Mage_Rule_Model_Condition_Combine because we wanted to avoid using the rewrite (which was for a third party module)

  • 1
    I got the same issue and fixed it with suggested. Thanks Commented Apr 24, 2019 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.