Home >Backend Development >PHP Tutorial >How to Fix the \'Strict Standards: Non-static method should not be called statically\' PHP Error?
The error message "Strict standards: Non-static method should not be called statically" occurs when a non-static method is accessed using a static invocation. To address this error, we will modify the code to ensure that all methods are declared as static when intended to be called statically.
In the provided code, the methods in the Page class are not declared as static, but they are being called as static. To resolve this issue, we need to add the static keyword to the method declarations.
Modify Page.php
class Page{ // ... public static function getInstanceByName($name=''){ // ... } // ... }
By making these methods static, they can be accessed using the class name, as seen in the index.php file:
// ... if($page){ // load by name $r = Page::getInstanceByName($page); if($r && isset($r->id)) $id = $r->id; } // ...
Additional Notes
The above is the detailed content of How to Fix the \'Strict Standards: Non-static method should not be called statically\' PHP Error?. For more information, please follow other related articles on the PHP Chinese website!