We did not declare the function as static, we can still use className::staticFunction
What you probably haven't noticed is that PHP complains about the second type of call:
Strict PHP standards: the non-static method Foo::helloWorld() should not be called statically in php shell code on line 1
Strict standards: the non-static method Foo::helloWorld() should not be called statically in php shell code on line 1
To make these notifications visible, you need to set the error_reporting value to -1 , either using ini_set() , or via the php.ini configuration file; By the way, this is recommended during development.
Conclusion
A function called statically must be declared as static function xyz() .
Update
Btw, using the scope :: operator does not necessarily mean that you are making a static call; consider this example:
class Foo { public function helloWorld() { print "Hello world "; } public function doSomething() { self::helloWorld(); } } $f = new Foo; $f->doSomething();
This works because using self:: unlike Foo:: does not change the call mode (unless the method you are calling is defined as static ).
source share