WP_DEBUG error caused by accessing static property as non-static
-
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
https://codex.www.ads-software.com/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 theWPRerouteEmail
object you define it as static:static $plugin_name;
Here’s a Stack Overflow issue about how to access static variables (
self::$var_name
):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!
- The topic ‘WP_DEBUG error caused by accessing static property as non-static’ is closed to new replies.