Cal Evans

Migrating to PHP 5.3

by Cal Evans |  22 comments | June 30, 2009

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)

Sharing links:
  • email
  • Twitter
  • Facebook
  • Digg
  • StumbleUpon
  • del.icio.us
  • LinkedIn
  • Technorati
  • DZone

22 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Nice migration article :)

  2. Wow, has it been 7 years since the introduction of PHP 5? Seems like just the other day….well, forget PHP 5.3, let’s bring on PHP6! :)

  3. Rich said

    Great informative article – summarises the changelog perfectly :-) thanks!

  4. IIRC, PHP 5 was released in the 2004.

  5. Jan said

    Nice overview, thanks for that.

  6. Jan said

    goto future;
    echo ‘PHP 5.2.x’;

    future:
    echo ‘PHP 5.3.x’;

    (Sorry, that was filtered out in my previous comment)

  7. Count me among the Teeming Millions who believe that the initial implementation of namespaces in 5.3 is badly broken.
    1) Use of the backslash as a separator is grossly counterintuitive; the implementor thereof should refrain from mind-altering substances while updating language specs;
    2) Why can’t ‘using’ do the job right? If I state that I’m using a namespaced entity, I should then be able to reference that entity as if it is in my current namespace; if I understand correctly, I’ve still got to include the innermost namespace, a backslash, and THEN the entity being referenced. Many, many hours of debugging will ensue from that implementation decision.
    3) Would it really have been that hard to support namespace definition and using clauses sprinkled throughout the source file, as in many, many other languages? Doing so would have given far greater flexibility to client code at what has to be minimal implementation cost.
    4) I could go on, but shooting fish in a barrel with a howitzer gets boring after the third shot or so…

    I have been an enthusiastic user of and evangelist for PHP for ten years now. I’m working on a Web-development book that features PHP (5.2). PHP 5.3 has dimmed my enthusiasm considerably. I expect that I will soon polish up my mod_python and Rails skills, with a view towards presenting alternatives to clients. I am quite sure I am not the only experienced PHP dev taking this decision.

Continuing the Discussion

  1. Ibuildings techPortal: Migrating to PHP 5.3 | DreamNest - Technology | Web | Net linked to this post on June 30, 2009

    [...] officially just launched but the Ibuildings crew has been preparing for it and have already posted this guide to help you make the migration up to this latest version. The good news is that if you’ve [...]

  2. Ibuildings techPortal: Migrating to PHP 5.3 | Webs Developer linked to this post on June 30, 2009

    [...] officially just launched but the Ibuildings crew has been preparing for it and have already posted this guide to help you make the migration up to this latest version. The good news is that if you’ve [...]

  3. Zend Framework in Action » PHP 5.3 is released! linked to this post on June 30, 2009

    [...] is a migration guide available, but you should also check out Cal Evans’ migration notes over at TechPortal [...]

  4. In PHP we Trust » Migrarea către PHP 5.3.0 linked to this post on June 30, 2009

    [...] pentru crearea şi îmbunătăţirea PHP-uluiâ Acest articol este o traducere a articolului Migrating to PHP 5.3.0 aparut in techPortal. migrare php, Php, php 5.3 Add your comment « Cache-uri [...]

  5. Community News: Responses to the PHP 5.3 Release | DreamNest - Technology | Web | Net linked to this post on July 1, 2009

    [...] a guide on the techPortal on making the upgrade [...]

  6. Ibuildings Blog linked to this post on July 1, 2009

    PHP 5.3 from a development manager’s perspective…

    Yesterday, the PHP community proudly announced that they have released PHP 5.3. While only the minor version number went up, this is still a significant release containing many new features. Maybe even more important than these new features are several…

  7. Community News: Responses to the PHP 5.3 Release | Webs Developer linked to this post on July 1, 2009

    [...] a guide on the techPortal on making the upgrade [...]

  8. Ibuildings Blog: PHP 5.3 from a development manager’s perspective | DreamNest - Technology | Web | Net linked to this post on July 2, 2009

    [...] a slightly different perspective – how development with it affects the management. At our Techportal Cal Evans gave an overview of the important changes, to make migration easier for developers. In [...]

  9. Ibuildings Blog: PHP 5.3 from a development manager’s perspective | Webs Developer linked to this post on July 2, 2009

    [...] from a slightly different perspective – how development with it affects the management. At our Techportal Cal Evans gave an overview of the important changes, to make migration easier for developers. In [...]

  10. M4d3L-Network Blog» Migration vers PHP 5.3 linked to this post on July 2, 2009

    [...] Migration vers PHP 5.3 02/07/2009 M4d3L Commenter Allez aux commentaires Cette articles est une traduction de « iBuildings – Migrating to PHP 5.3«  [...]

  11. PHP 5.3 from a development manager’s perspective – techPortal linked to this post on July 7, 2009

    [...] our Techportal Cal Evans gave an overview of the important changes, to make migration easier for developers. In [...]

  12. Migración a PHp 5.3: primeras experiencias linked to this post on July 10, 2009

    [...] hacer la migración me he basado en: http://techportal.ibuildings.com/2009/06/30/migrating-to-php-5-3/. [...]

  13. phpLiveDocx is compatible with PHP 5.3 linked to this post on August 14, 2009

    [...] Migrating to PHP 5.3 – Cal Evans [...]

  14.   ¿Qué hay de nuevo en PHP 5.3? by Pecesama.Net [weblog] linked to this post on August 21, 2009

    [...] PHP for Professional Developers [...]

  15. WordPress 2.8.x und PHP 5.3 | Webseiten-Infos.de linked to this post on September 7, 2009

    [...] Migrating to PHP 5.3 bei techportal.ibuildings.com [...]