Non-Static Method Invocation
The error encountered, "Error message Strict standards: Non-static method should not be called statically," occurs when a non-static method is invoked as if it were a static method.
In your provided PHP code, the issue lies within the Page class. The methods getInstanceByName() and getInstanceBySpecial() are defined as non-static methods, which means they must be invoked using an instance of the Page class. However, you are trying to call them as static methods, without an instance of the Page class.
Solution
To resolve this issue, you need to make the methods static by adding the static keyword to their declarations. Change:
function getInstanceByName($name='') {
to:
public static function getInstanceByName($name='') {
Similarly, modify the getInstanceBySpecial() method to also be static.
Once you have made these changes, you should be able to call getInstanceByName() and getInstanceBySpecial() as static methods, without getting the error.
The above is the detailed content of Why Am I Getting \'Strict Standards: Non-static method should not be called statically\' in PHP?. For more information, please follow other related articles on the PHP Chinese website!