PHP 5.3 and Drupal 6 don't play nice... yet

Apparently Drupal 6 is not yet PHP 5.3 compliant. I noticed this today while updating a Drupal couple modules. When I wanted to run update.php I got a nice white screen with tons of messages about the ereg method.
Indeed, PHP 5.3 marked ereg regular expressions as obsolete, since other regular expression libraries work better or are more portable, such as preg (Perl-compatible regular expressions). One big difference between both, is that preg regular expressions have to be enclosed with regular expression pattern termination characters (the default often is a forward slash ‘/’, but any character is OK).
To get my Drupal back on-line, I had to manually edit includes/ and hunt for 2 occurrences of ‘ereg’ in that file:

  • at line 642: replace ereg_replace with preg_replace and add forward slashes as pattern termination character so it reads:$regex = '/\.('. preg_replace('/ +/', '|', preg_quote($extensions)) .')$/i';
  • at line 910: replace ereg with preg_match and add pound signs ‘#’ as pattern termination character so it reads:elseif ($depth >= $min_depth && preg_match("#$mask#", $file)) {

The deprecation of ereg regular expressions is only one of the big changes introduced in PHP 5.3. Another important change is a more rigorous check of by-value versus by-reference argument passing in method calls.
The impact of PHP 5.3 on Drupal 6 is documented in the following Drupal bug report: [drupal] [bug] PHP 5.3 Compatibility.
The upcoming Drupal 7 code base will be PHP 5.3 compliant, but it now appears Drupal 6 (and who knows, Drupal 5 as well) may have to be ported to PHP 5.3 earlier than anticipated.
So far for today Smile

Olivier Biot's picture

Some modules no longer function properly

Since upgrading to PHP 5.3 a couple modules no longer function properly. One example is the Diff module which suffers from the stricter parameter type checking.
This stricter parameter checking may well result in a Drupal API change in version 6.
It appears a joint effort will be needed to make Drupal core as well as its plethora of contributed modules PHP 5.3 compatible.

ilahi's picture


good blog really and great sharing thank you

Nemo's picture


Great post Thank you admin

memur's picture

thank you

Thank you great post admin :)

Guy's picture

Still not compatible

I'm still having issues with D6 on PHP 5.3, so a year after this post, little has changed.

JOn's picture

Will Drupal 6.22 and PHP 5.3 work?

Today I upgraded to Drupal 6.22 after my web host announced that they are upgrading PHP in October. Now I am worried that it still will not work.
I cannot upgrade to Drupal 7 yet as I got an error message "Drupal 7 requires PHP 5.2.4 or higher with the PHP Data Objects (PDO) extension enabled."
Is 6.22 a "fixed" version?

Olivier Biot's picture

Re: Is 6.22 a "fixed" version?

Today the Drupal developer community develops Drupal 7 and maintains Drupal 6, so you should be safe. This means that if other Drupal core vulnerabilities are identified in Drupal 6, that you will see a new Drupal 6 bugfix release appear.
Drupal 7 requires MySQL5 and the PDO extension enabled.
Many Drupal deployments use Drupal 6 today. When Drupal 8 will be officially released, Drupal will officially stop supporting Drupal 6. I am not aware of a Drupal 8 timeline yet, so you should be safe running Drupal 6 for a while still.

kurs's picture


i like this write.

Matt Considine's picture

I'm still having issues with

I'm still having issues with D6 on PHP 5.3 i hope this could be resolve immediately.  Underwater Photographer

Olivier Biot's picture

Re: I'm still having issues with

Which problems are you facing? Are you unable to install Drupal on your host?

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.