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
  • 13,000
  • 8
  • 46
  • 72

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
  • 8,516
  • 2
  • 29
  • 35