I thought usually we use static method because we do not need to instantiate objects. and we can use className::staticFunction
to call static method, bub today found:
test1.php
<?php
class Foo {
static public function helloWorld() {
print "Hello world " ;
}
}
Foo::helloWorld();
test2.php
<?php
class Foo {
public function helloWorld() {
print "Hello world " ;
}
}
Foo::helloWorld();
Question:
Both of above scripts work. We did not declare function as static
, we can still use className::staticFunction
to call the function. Why do we need use static methods?