Static And Not Static Method¶
Could PHP have both a static and a non-static method, with the same name?
PHP accepts to have several signatures for the same method, yet this has to be handled with different tools, in the body of the function.
On the other hand, since methods must have a unique name, it must be either static or non-static.
To support both static and non-static method calls, the first step is to… remove the methods with the target name: PHP always uses the available method first.
Then, replace them with two calls to magic methods: __call and __callStatic. These two magic methods are called depending on the style of the call: static or not static.
While this is a rather academic question, it might be a useful feature when migrating from a static class to a normal one, while keeping backward compatible syntax.
See Also¶
Same method, different static [Try me]