Home > Backend Development > PHP Tutorial > Why Am I Getting \'Strict Standards: Non-static method should not be called statically\' in PHP?

Why Am I Getting \'Strict Standards: Non-static method should not be called statically\' in PHP?

Susan Sarandon
Release: 2024-11-24 06:04:12
Original
839 people have browsed it

Why Am I Getting

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='') {
Copy after login

to:

public static function getInstanceByName($name='') {
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template