Hassan Hassan - 1 year ago 91
PHP Question

why I keep getting "Fatal error: Call to undefined function getCountries()" in php oop?

I am beginner in php OOP but I have created a class called countries as the following:


class countries {
public $countries = array("Afghanistan","Hong Kong","Moldova","Malawi");

public function getCountries() {
return $countries;


$country = new countries();


Answer Source

Just change it, use $this-> if you don't call static function or variable. In your situation to get array values with $this->

public function getCountries() {
   return $this->countries;

and also call function from class without - {braces}, for instance, $class->function_name();

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download