• Home

Logo

Navigation
  • Home
  • Articles
    • Content Writing
    • Design
    • General
    • Internet Marketing
    • Social Media
    • Tools and Tips
    • Usability
    • Web Hosting Articles
  • Tutorials
    • AJAX Tutorials
    • ASP Tutorials
    • C# Tutorials
    • CGI and Perl Tutorials
    • CSS Tutorials
    • Flash Tutorials
    • HTML Tutorials
    • Illustrator Tutorials
    • Java Tutorials
    • JavaScript Tutorials
    • Linux Tutorials
    • Miscellaneous Tutorials
    • MySQL Tutorials
    • Photoshop Tutorials
    • PHP Tutorials
    • Python Tutorials
    • Wireless Tutorials
    • WordPress Tutorials
    • XML Tutorials
  • Scripts
    • AJAX Scripts
    • ASP Scripts
    • ASP.NET Scripts
    • CGI & Perl Scripts
    • Flash Scripts
    • Java Scripts
    • JavaScript Scripts
    • PHP Scripts
    • Python Scripts
    • Remotely Hosted
    • Tools and Utilities
    • XML Scripts
  • Answers
  • Online Services
  • Tools

Migrating legacy PHP 4 applications to PHP 5

By Akash Mehta | on Jul 10, 2008 | 0 Comment
PHP Tutorials
  • Tweet
  • Share
  • Tweet
  • Share

As Ivo Jansch pointed out on the Ibuildings blog, there’s barely a month left till security fixes are discontinued for PHP 4. While support for PHP 4 officially ended last December, security updates were offered until 08-08-08. Most major web hosts have been phasing out PHP 4 support, but many legacy applications built with PHP 4 in mind are currently in use, and the more intricate will take quite some time to move to PHP 5. Here are some tips and resources for managing the migration process.

PHP 5 supports most of the legacy syntax features of PHP 4. Most code written for PHP 4 should function fine under PHP 5, and a comprehensive test suite could check this. However, many of the backwards-incompatible changes in PHP 5 were in regard to language quirks, and quite a few hacks rely on these in order to function. Here are some issues to watch out for:

  • Class names provided by language features – get_class(), get_parent_class() and get_class_methods() now return the name of the classes/methods exactly as declared; earlier, they were lowercased first
  • The new object model is quite different – an empty object is no longer considered “empty” by empty(), among other changes
  • Files with functions cannot be included twice; PHP 5 throws an error as the function is being redeclared
  • Illegal uses of string offsets (e.g. $somestring[0]) will throw an error
  • On Windows servers, the include/require_once functions are case insensitive – “SomeFile.php” and “somefile.php” will only be included once

Legacy applications making use of the CLI, especially under Windows, should be aware of the new names for binaries. The CGI binary has been renamed to php-cgi (previously php), while the CLI binary has been moved back into the main directory as php. Other applications calling PHP scripts may also want to look at php-win on Windows, which serves the same function as the CLI except without the black “DOS box”.

Finally, there are some new reserved keywords. If you are upgrading straight to PHP 5.3, watch out for the new namespace keywords, including “namespace”, “use” and __NAMESPACE__. The new OOP features introduce quite a few keywords popular in enterprise applications – “public”, “private”, “protected”, “clone”, “try” and “this” come to mind (more available here). Error checking every file (run “php -l /path/to/file.php”) can pick these up fair quickly.

PHP 4 has been discontinued for some time; indeed, the latest release, 4.4.8, is from early January. Major legacy applications should be ported as quickly as possible to avoid security issues; existing code should be thoroughly checked for syntax and language feature changes as well. The PHP manual has some handy documentation on migrating, and the PHP 5 features are clearly noted all around the manual – check the revision history of functions as well.

Share this story:
  • tweet

Author Description

No Responses to “Migrating legacy PHP 4 applications to PHP 5”

You must be logged in to post a comment.

Connect With Us

RSSSubscribe 0Followers 492Likes
  • Popular
  • Recent
  • Comments
  • Creating Energy Spheres in Photoshop

    Apr 15, 2008 - 96 Comments
  • Easy Screen Scraping in PHP with the Simple HTML DOM Library

    Aug 6, 2008 - 20 Comments
  • Calculating date difference more precisely in PHP

    Mar 7, 2008 - 13 Comments
  • When Does Hosting Your Website in the Cloud Make Sense?

    Oct 8, 2010 - 2 Comments
  • Fun with the Microsoft Managed Extensibility Framework Part 2

    Oct 6, 2010 - 0 Comment
  • Fun with the Microsoft Managed Extensibility Framework Part 1

    Sep 22, 2010 - 0 Comment
  • Website Management on the go with the iPad

    I appreciated your post, but I was looking for something I didn't...
    November 24, 2012 - drmoderator
  • Creating Energy Spheres in Photoshop

    I'm a little stuck down here especially at the step of creating the...
    November 23, 2012 - sarah
  • Running background processes in PHP

    Can you give an example? As see it, you can use this only when you...
    November 16, 2012 - Shaked Klein Orbach
Developer Resources
  • Tutorial Directory
  • Learn HTML
  • Learn PHP
  • Learn CSS
  • Learn AJAX
  • Learn JavaScript
  • Learn Pear
  • White Papers
  • Resources
    • NetVisits Web Directory
    • Realtor Pixels
    • Answers On The Run
    • Ask A Geek
  • Recent Posts

    • When Does Hosting Your Website in the Cloud Make Sense?
    • Fun with the Microsoft Managed Extensibility Framework Part 2
    • Fun with the Microsoft Managed Extensibility Framework Part 1
    • Website Management on the go with the iPad
    • Code Contracts in C# 4.0 – Part 1

    Calendar

    May 2013
    M T W T F S S
    « Oct    
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  

    Recent Comments

    • drmoderator on Website Management on the go with the iPad
    • sarah on Creating Energy Spheres in Photoshop
    • Shaked Klein Orbach on Running background processes in PHP
    • Thomas Cuvillier on How To Upload Files Using PHP
    • rizal aditya on Extracting text from Word Documents via PHP and COM
    • Home
    © 2003 - 2013 DeveloperTutorials.com. All Rights Reserved. Privacy Policy.