I'm trying to use PHP's scope resolution operator to access the bar() method without instantiating the Foo class:
<?php class Foo { public function bar() { return 'bar'; } } echo Foo::bar;
But I'm getting:
PHP Fatal error: Uncaught Error: Undefined class constant 'bar'
What am I doing wrong?
You can't 'access' methods, you can only call them. Also, the method should be marked static:
<?php class Foo { static function bar() { return 'bar'; } } echo Foo::bar();
1.4m articles
1.4m replys
5 comments
57.0k users