Calling a non-static method statically
Theoretically, this should not work, but as this comment says:
There was no static keyword in php4, but php4 allowed static calls. For backward compatibility, this was abandoned when the static keyword was added in php5.
This comment is supported by this official php.net wiki:
This is no longer recommended if the call comes from an instance method. Not annotating methods as static - this is deprecated PHP4-rev.
You really shouldn't call the non-static method statically - that doesn't make sense (if there is a static ).
Try not to call non-static methods statically completely!
... because a) this is a bad approach and b) PHP documents say:
precaution
In PHP 5, calling non-static methods statically generates an E_STRICT level warning.
AND
A warning
In PHP 7, static invocation of non-static methods is deprecated and generates an E_DEPRECATED warning. Support for static invocation of non-static methods may be removed in the future.
Using the :: operator for non-static calls can be a good approach!
As @Kontrollfreak pointed out and as they say in this documentation , the :: operator is not limited to static calls:
double colon is a token that allows you to access static, constant and overridden class properties or methods
So everything is fine if you refer in this way to a method or properties of the parent class, which is not limited to the direct parent.
EDIT: do not confuse this with Fascade software templates, etc.!
While writing this answer, I forgot to mention that there may be cases when the call is static, but inside it calls the dynamic method - for more information, see Templates such as Facade or Singleton .
However, DO NOT confuse this with the problem described above! (the problem above is about using a direct static call for a dynamic object that needs to be called dynamically, these templates are designed to static call static methods, which can then dynamically call something dynamic (internally)).
jave.web
source share