PHP7 Compatibility EASY FIX use __construct()
-
PHP7 has a new deprecation warning that forces us to define classes slightly differently. Rather than being able to use the class name as the label for the constructor method, the constructor method must be called
__construct()
. PHP7 is about to explode in popularity because it is terrifically faster than PHP5 and the new Ubuntu LTS version featuring PHP7 is about to see final release.Here’s the type of error I get from Google Analyticator running on PHP7:
( ! ) Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; GoogleAnalyticsStats has a deprecated constructor in /[…]/wp-content/plugins/google-analyticator/class.analytics.stats.php on line 8
They happen all over the site when WP_DEBUG is enabled because just loading that code into memory triggers it, so it’s extremely important that the warnings be removed, as it will fill up the server logs of anyone who uses the plugin.
The solution is super simple, and just requires you to match the code style to what the rest of WP has already done (in
class.analytics.stats.php
):/** * HOTFIX: Replace class name as constructor with __construct() */ // function GoogleAnalyticsStats() function __construct()
Here are the places in your plugin that need updating:
google-analytics-summary-widget.php:
//function GoogleAnalyticsSummary($shortcode = FALSE) function __construct($shortcode = FALSE)
google-analytics-stats-widget.php:
//function GoogleStatsWidget($shortcode = FALSE) { function __construct($shortcode = FALSE) {
and the class.analytics.stats.php example above.
Thank you for fixing this if you can. Please review the other tickets about notices/deprecation in your plugin as there are several other EASY fixes that would mean I could start using the vanilla version of your plugin again.
- The topic ‘PHP7 Compatibility EASY FIX use __construct()’ is closed to new replies.