[wp-hackers] Testing for PHP 5 before activating

Otto otto at ottodestruct.com
Mon Jul 12 17:21:24 UTC 2010

On Mon, Jul 12, 2010 at 9:29 AM, Andrew Nacin <wp at andrewnacin.com> wrote:
> Keep the rest of your plugin in a second file and only include it when you
> know you can support it.


I had to eventually do the same thing with Simple Facebook Connect,
because people simply don't read requirements.

The problem is that try/catch is invalid syntax in PHP 4 and will
cause an error on activation, and the activation handler can't prevent
it. The only way to do it is to include a check and load a separate

Basically, I did this:

// this will prevent the PHP 5 code from causing parsing errors on PHP 4 systems
if (!version_compare(PHP_VERSION, '5', '<')) {
	include 'sfc-base.php';

Then moved all the rest of the code (minus the activation check) into


More information about the wp-hackers mailing list