• Mike

    (@maltesesolutions)


    I am converting one of my plugins to Class instead of functions and I am encountering an error. PHP classes are fairly new to me so I am having some trouble.

    I am getting the following error:
    Fatal error: Using $this when not in object context in … on line 207

    Here is the method inside the class:

    public function getLocations(){
    
    		$Locations = $this->db->get_results("select location_id, location FROM {$this->my_locations_db}");
    
    		return $Locations;
    
    	}

    Line 207 starts with $Locations

    I am calling the method from inside the class using:

    // get all the locations
    		$myLocations = self::getLocations();

    I am calling this same method through another method without a problem.
    I am getting the results I am seeking, however when I call it from a different method I get the error.

    Your help would be greatly appreciated.

    Thanks

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The self:: syntax is to reference static properties.
    Use $this-> syntax for variable properties and methods.
    $myLocations = $this->getLocations();

Viewing 1 replies (of 1 total)
  • The topic ‘Help with a class’ is closed to new replies.