• eml: contact@sevenforty.com
  • tel: 1-866-620-7524
  • fax: 703-652-4788

    A Few Things about PHP 5.3

    Recently we upgraded our development environment to the latest and greatest stable version of PHP 5.3. Of course with almost any update come the usual questions of what is backwards compatible, what has been deprecated and what flat out will break your carefully crafted software. However, one great gem of previous PHP 5.x versions is that they usually had minimal impact on existing code and were surprisingly backwards compatible friendly. Rarely did we ever come across anything that we would raise an eyebrow to and as such, when upgrading to PHP 5.3, we expected little headaches. Turns out, this would not be the case.

    While this may sound like we are going to write a long thesis over the headaches (if you want to consider them headaches) of PHP 5.3 or how it will break every line of PHP code you have ever written in the past (don’t worry it won’t), this fortunately will not be the case. Instead, what we present here are a few helpful tips in case you decide to migrate to PHP 5.3 (which we suggest you do eventually) and are left scratching your head as to why a particular web application installation won’t work or why your dev environment now fails to run PHP in Windows.

    A few big changes in PHP 5.3 (at least what we feel is big):

    1. Namespaces – Yes they are here and we did not need to wait for PHP 6. Let’s start using them already.

    2. Dates – You must specify a default timezone in your PHP.ini. Without it, the date function will flop like the Matrix sequels. You can pick up a list of timezones to set here: http://www.php.net/manual/en/timezones.php

    3. __toString() – The toString magic function no longer accepts arguments. Better yet avoid magic methods all together or use them sparingly to say the least. Check your error logs for lines such as:

    PHP Fatal error: __tostring() cannot take arguments in…

    A few well known applications (that we will not mention by name) running around out there utilize such methods and will give you the “blank screen of death.”

    4. mysql_escape_string() – It’s now deprecated, start using mysql_real_escape_string() in your database abstraction layers. You are using a database abstraction layer, right?

    5. ereg() et al – Deprecated…why were you using this anyways?

    These are just a few of the many changes found in PHP 5.3 and were some of the key items that caused us some issues or that we thought were noteworthy. If you do have trouble with your PHP code and environment after migrating to 5.3, we do suggest you look for some of the items we mentioned above and run through the 5.3 migration documentation. It won’t be a tough migration, but we did find a few caveats that took us a bit to uncover and address.

    Posted by Stephan in


    Add a Comment

      You must PREVIEW your comment before posting.