As PHP developers download and start testing the biggest change to the language in 7 years, many are wondering not about Santa’s bag full of new toys for them to use in building tomorrow’s applications but about the changes in the language that will affect yesterday’s applications.

The good news is that if you’ve been keeping your applications current with the language and best practices, there are very few things that could affect you. The bad news is that the farther away from the current version of the language you get, the harder it is going to be to port your code. For developers coding against the 5.2 branch, there are a few edge case situations of which, you need to be aware.

What follows is not a list of all the new features in PHP 5.3, there are many good references around the web for that information. The following is a distillation of the PHP 5.3 migration guide. We only cover those items most likely to affect legacy 5.x code.

Array Processing Functions

Previous to 5.3, many of the array processing functions could take either an object or an array and work. With 5.3, many of them change to array only. If you want to access an objects properties with one of the following functions, you will need to cast the object to an array first.

Change to Magic Methods

Previous to 5.3 the magic methods could be declared as something other than public.

  • __get()
  • __set()
  • __isset()
  • __unset()
  • __call()

Starting with PHP 5.3, these methods have to be declared as public and cannot be declared as static.

Deprecated

PHP has a list of functions that have been marked for removal. Most of these aren’t in common use but if you have legacy code, you may want to scan for them. The functions marked as deprecated are:

Additionally, several directives in the PHP.INI file have been deprecated. If activated, they will now emit an E_DEPRECATED warning.

  • define_syslog_variables
  • register_globals
  • register_long_arrays
  • safe_mode
  • magic_quotes_gpc
  • magic_quotes_runtime
  • magic_quotes_sybase

Since anything emitting an E_DEPRECATED warning will potently be removed from the next version of the language, these are hints to developers about to what to start looking at for PHP 6.

Undeprecated

In 5.0, the is_a() was deprecated in favor of instanceof, however, it was not removed from the language. In 5.3, that decision is reversed and is_a no longer throws an E_DEPRECATED warning.

Reserved

The following two keywords are now reserved:

Given the nature of these two keywords, it is doubtful that they exist often in legacy code. However, it is probably a good idea to scan legacy code looking for them. If they do exist, they will cause the parser to throw a parse error. They cannot be used as function names, class names, etc.

Conclusion

That is it. The complete PHP 5.3 migration guide can be found in the documentation on php.net. There aren’t many things in PHP 5.3 that will prevent well written PHP 5.x code from running. PHP 5.3 is much more about adding to the language than subtracting. If you are worried about your code not working in PHP 5.3 or would like to see how the new features of PHP 5.3 can help streamline your code and make your systems run faster, Ibuildings offers a range of code auditing and consulting services and are eager to assist you.

 

 

Thank you

It often goes without saying that we appreciate the hard work that everyone who contributes to PHP put in. I don’t think it should go without saying though. I think everyone should personally thank the developers who put their time in to make PHP. So on behalf of all of us here at Ibuildings, thank you PHP core team. (Phergie, beer core devs)