• Resolved Jer Clarke

    (@jeremyclarke)


    Hi, there thanks for the plugin!

    There’s a bug that happens on the plugins page and generates several errors if WP_DEBUG is enabled. WP_DEBUG makes PHP use strict warnings which is good for catching errors in your code that cause problems, but also requires you to sometimes fix issues that weren’t breaking anything (like this case). Learn more about WP_DEBUG

    http://codex.wordpress.org/Debugging_in_WordPress

    Here are the warnings generated by your plugin (on the list-all-plugins page, PHP 5.4.26):

    ( ! ) Strict standards: Accessing static property WPRerouteEmail::$plugin_name as non static in /../wp-content/plugins/wp-reroute-email/wp-reroute-email.php on line 141

    ( ! ) Notice: Undefined property: WPRerouteEmail::$plugin_name in /../wp-content/plugins/wp-reroute-email/wp-reroute-email.php on line 141

    ( ! ) Strict standards: Accessing static property WPRerouteEmail::$plugin_name as non static in /../wp-content/plugins/wp-reroute-email/wp-reroute-email.php on line 142

    They are all caused by WPRerouteEmail->add_settings_link( ) because it accesses $this->plugin_name as a normal property, even though at the top of the WPRerouteEmail object you define it as static:

    static $plugin_name;

    Here’s a Stack Overflow issue about how to access static variables (self::$var_name):

    http://stackoverflow.com/questions/9691008/access-static-property-through-static-and-non-static-methods

    Here’s how add_settings_link looks with the correction:

    public function add_settings_link($links, $file) {
    
    		  if (is_null(self::$plugin_name)) {
                self::$plugin_name = plugin_basename(__FILE__);
            }
    
            if ($file == self::$plugin_name) {
                $settings_link = '<a href="options-general.php?page=wp-reroute-email/settings.php">' . __('Settings', 'wp_reroute_email') . '</a>';
                array_unshift($links, $settings_link);
            }
    
            return $links;
        }

    Thank you in advance for working this fix into the next version of the plugin! You may also want to consider removing the ‘static’ keyword instead, though that depends on why you used it of course.

    Keep up the good work!

    https://wordpress.org/plugins/wp-reroute-email/

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP_DEBUG error caused by accessing static property as non-static’ is closed to new replies.