1

I got this error, i cant figure whats problem. My code is

class Example{
     public function get_lang()
        {
            $jezik = get_option('jezik');
                     switch ($jezik ) {
                         case $jezik == 'rs_RS':
                         $drzava = 'NazivSrb';
                         break;
                         case $jezik == 'ro_RO':
                         $drzava = 'NazivRo';
                         break;
                         case $jezik == 'uk_UK':
                         $drzava = 'NazivRu';
                         break;
                    }
            return $drzava;        
        }

    static public function ExecuteSql($where_criteria=NULL) {
            global $wpdb;

                   $drzva = $this->get_lang();

            $upit = "
                            SELECT ID, Naziv, $drzava, PhoneCode, Kod
                    FROM wp_drzava";
            if ($where_criteria)
                $upit .=" WHERE ". $where_criteria ;
            $upit .= " GROUP BY Kod";
            //echo $upit;
            return $wpdb->get_results($upit);
        }

{

Basically I try to use get_lang method return value, and save it to variable in other method, and pass it to query. But i get an error in this line

$drzva = $this->get_lang();

2 Answers 2

1

You can't use $this inside static method.. use self keyword if you want to use same class method inside static method

self::get_lang();

EDIT: get_lang() should static method, if you are not using class properties inside method.

Sign up to request clarification or add additional context in comments.

3 Comments

In this case, get_lang() should be static.
you can call non static method like self::callmethod while another method (get_lang()) not used $this inside method. static method is independent, you can call without create class object
get_lang() static method is accessible via public ExecuteSql method, self:: will also work
0

You cannot use $this in a static public function ($this does not exist in it).

To fix this, use:

$example = new Example;
$drzva = $example->get_lang();

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.