radishconcepts / WordPress-GitHub-Plugin-Updater

This class is meant to be used with your Github hosted WordPress plugins. The purpose of the class is to allow your WordPress plugin to be updated whenever you push out a new version of your plugin; similarly to the experience users know and love with the WordPress.org plugin repository.
https://github.com/jkudish/WordPress-GitHub-Plugin-Updater
822 stars 195 forks source link

Using class_exists with else can cause issues #49

Closed afxdesign closed 9 years ago

afxdesign commented 11 years ago

Hi,

I have to admit I came across this bug when amending my own plugin code to use your class_exists syntax - previously I had wrapped the class in the else also e.g:

if ( class_exists( 'WPGitHubUpdater' )  ) return;

After doing this I started getting random class redeclaration errors. After a lot of investigation I realised it was because xcache was causing the class to be loaded before the return statement. In essence it incorrectly scopes the class outside the return statement.

There are youtube videos demonstrating the problem at stackoverflow: http://stackoverflow.com/questions/17603403/php-cannot-redeclare-class-error-after-return

It caused me a massive headache trying to work out what was going on. As xcache is used a lot in the wild I thought you might like to know. I would recommend setting up a autoloader or wrapping the class in else tags e.g.

if ( class_exists( 'WPGitHubUpdater' )  ) return;
else {
    class WPGitHubUpdater {
        ...
    }
}
coenjacobs commented 9 years ago

As also explained in #51, I'd rather not wrap the entire class in such an if statement, as that's not the solution but just patchwork. We'll look into a proper autoloader as we approach 1.6, which should tackle this issue.