Why I am dropping support for PHP 5.2 in my WordPress plugins

I have decided to drop support for PHP 5.2 in my WordPress plugins. I have thought about it for quite sometime and even hinted about it in the last couple of my posts.

I am writing this blog post to explain the reasons behind my decision. The following are the two main reasons why I decided to drop support.

Bad Coding Style

This is the primary reason for me (even though it may sound a little selfish) to drop support for PHP 5.2 in my WordPress plugins.

Let me explain what I mean by bad coding style.

Any code that you are writing for WordPress, whether it is a theme or a plugin, has to work together with code from other plugins or themes. This means that you have to make sure that the name you give to your function is not used by any other plugin or theme.

PHP 5.3 added support for Namespace and closures to address the name collusion issue. But in PHP 5.2 there are no built-in way to fix this problem. Developers have invented their own ways (hacks) to handle this issue.

The most common approach is to add a prefix to all your functions and add a function_exists() wrapper, or worse, enclose all these (non-related) functions inside a class to avoid name collusion. This defeats the fundamental purpose of Object Oriented Programming and is one of the main reasons why non-WordPress PHP developers hate WordPress developers.

Pretty much most of my WordPress plugins have a class just to avoid name collusion. Every time I do this I am left with a feeling of imperfectness. I have waited for WordPress to support PHP 5.3 so that I can use either Namespace or closures to avoid this. This feeling of imperfectness coupled with the fact that support for PHP 5.2 (and even PHP 5.3) is now unsupported, has pushed me to make this reason.

Now that we have seen the selfish reason, let’s see the other (slightly noble) reason 😉

PHP 5.2 is old, in fact very old

As I mentioned above PHP 5.2 is very old. It was released in Nov 2006 and support for it ended in Jan 2011. That means WordPress is supporting a software whose development stopped 4 years ago. In the web development world, that’s a very long period.

For the record, even support for PHP 5.3 has ended in Aug 2014. You can find the release and support dates for all PHP releases in the wikipedia article about PHP.

I am not saying that we shouldn’t use something just for the reason that it is old, but the main reason we shouldn’t use it is because support for it has ended. If a security issue is found then it will not be fixed. In the web development world running outdated and vulnerable code is asking for trouble.

By forcing my users to update from PHP 5.2 I am doing my bit to make the Internet a little safer (at least in my opinion).

You may feel that changing minimum requirement to PHP 5.3 (or above) might break the websites that are still running PHP 5.2, but I don’t think so. Instead it could be the other way around. Ozh summarized it in a single sentence when he wrote about why WordPress should stop supporting PHP 5.2, a year ago.

The day WordPress says “we require PHP 5.3”, the whole web which is still running 5.2 switches to 5.3. Simple as that.

Transition for my plugins

The following is my plan to transition my plugins to PHP 5.3.

I am not going to rewrite all my WordPress plugins to support only PHP 5.3, that’s a huge amount of wasted effort. If the plugin is already working then I am not going to make any change to it. But if I am going to create a new plugin or making significant changes to the codebase to add new features, then I am not going to restrict myself to support PHP 5.2. Also, going forward I am not going to test my plugins in PHP 5.2.

This means that some of my plugins might continue to support PHP 5.2, but I am going to make it clear that PHP 5.3 or above is recommended and the code is not guaranteed to work in PHP 5.2.

If you strongly feel that I should support PHP 5.2 then I am very interested in knowing your views. Also if you are a WordPress plugin or a theme developer, then I am interested in knowing your view on this as well. Please leave a comment below about your own views on this.

Together, let’s hope that the powers behind WordPress make the decision to move away from PHP 5.2 before it is too late.

Related posts

Tags: ,

4 Comments so far

Follow up comments through RSS Feed | Post a comment

  • Dave Ross says:

    I agree with everything here. I’m re-writing one of my plugins from scratch and this is one of the things I’ve been considering as well. There’s syntactic sugar in PHP 5.3 and 5.4 that I want to try out. Specifically, things like closures and __invoke() which permit a more functional style of programming.

    I only hesitate because I remember the hassles I had when I made the first versions of this plugin “PHP 5 only”.

    • Sudar says:

      I only hesitate because I remember the hassles I had when I made the first versions of this plugin “PHP 5 only”.

      I agree with this and this was one of the reasons why I struck with PHP 5.2 till now. Even though I acknowledge this, unfortunately I don’t have an answer to this problem 🙁

  • H Sudar,

    I could not agree with you more; the sooner WordPress drop PHP 5.2.4, the better. (I think is will probably be dropped at some point this year).

    Even PHP 5.3 is past its end of life – http://php.net/eol.php

    For my WordPress repository plugins I comply with PHP 5.2.4 however for my more complex premium plugins I moved on to PHP 5.3 minimum dependency with no resistance at all from plugin users.


    • Sudar says:

      Hi Russell,

      Thanks for sharing your experience with your users after making a move to PHP 5.3. Even I had similar experience.

      Together let’s hope that WordPress drops PHP 5.2.4 soon.

Leave a Reply

Your email address will not be published. Required fields are marked *