1
class Foo {
  public function bar($thing) {
    return $thing * 2;
  }
}

echo Foo::bar::(4);

The code above shows this error:

Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM

Could you tell me why? I am new to php. Thank you very much!

We Are All Monica
  • 12,312
  • 7
  • 43
  • 71

1 Answers1

1

To call a class method without an instance you need to make it static. Also the last "::" are too much.

class Foo {
    public static function bar($thing) {
        return $thing * 2;
    }
}

echo Foo::bar(4);
Markus Zeller
  • 5,528
  • 2
  • 29
  • 32