• PHP 8.0 no longer allows to call non-static class methods with the static call operator (::). Both the methods NY_OG_Main_Admin::option and NY_OG_Main_Admin::set_options are only called statically in the source code, they should therefore both be marked with the keyword “static”. Or error similar to this will happen:

    PHP message: PHP Fatal error:  Uncaught Error: Non-static method NY_OG_Main_Admin::option() cannot be called statically in /var/www/foobar/wp-content/plugins/wp-open-graph/output.class.php:29
    Stack trace:
    #0 /var/www/foobar/wp-includes/class-wp-hook.php(287): NY_OG_Output->add_og_elements()
    #1 /var/www/foobar/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters()
    #2 /var/www/foobar/wp-includes/plugin.php(478): WP_Hook->do_action()
    #3 /var/www/foobar/wp-includes/general-template.php(3009): do_action()
    #4 /var/www/foobar/wp-content/themes/sometheme/header.php(29): wp_head()
    #5 /var/www/foobar/wp-includes/template.php(730): require_once('...')
    #6 /var/www/foobar/wp-includes/template.php(676): load_template()
    #7 /var/www/foobar/wp-includes/general-template.php(48): locate_template()
    #8 /var/www/foobar/wp-content/themes/sometheme/404.php(10): get_header()
    #9 /var/www/foobar/wp-includes/template-loader.php(106): include('...')
    #10 /var/www/foobar/wp-blog-header.php(19): require_once('...')

    I’ve created a patch for the plugin that seems to work:

    From 45947335e076553d3c459577573f1f110bb090e3 Mon Sep 17 00:00:00 2001
    From: Koala Yeung <[email protected]>
    Date: Mon, 21 Jun 2021 12:13:23 +0800
    Subject: [PATCH] Fix static function signatures for PHP 8.0
    
    * Statically called functions should have the "static" keyword.
    ---
     main.admin.class.php | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/main.admin.class.php b/main.admin.class.php
    index 64b2b31..fcc0011 100644
    --- a/main.admin.class.php
    +++ b/main.admin.class.php
    @@ -29,11 +29,11 @@ class NY_OG_Main_Admin {
             add_action( 'admin_menu', array( __CLASS__, 'wpog_add_pages' ) );
         }
    
    -    public function option( $name ) {
    +    static public function option( $name ) {
             return isset( self::$options[$name] ) ? sanitize_text_field( self::$options[$name] ) : null;
         }
    
    -    public function set_options( $options ) {
    +    static public function set_options( $options ) {
             self::$options = array_merge( self::$options, $options );
    
             update_option( 'wpog_options', self::$options );
    -- 
    2.17.1
    • This topic was modified 3 years, 9 months ago by Koala Yeung.
  • The topic ‘PHP 8.0 fix for’ is closed to new replies.