You are here

Drupal and PHP 5.3

There are some problems with running Drupal on php 5.3. There are five kinds of solutions:

  1. Downgrade to php 5.2.6 (not possible in many situations)
  2. modify Drupal to change the error level reporting
  3. find the latest patches to fix the problems
  4. hack Drupal core or contrib yourself to fix the errors (Drupal 6 is already compliant, but not D5)
  5. put a timezone in your php.ini to get rid of timezone errors

Drupal 6

2. Modify Drupal's error reporting --already done for Drupal 6

3. Find patches

Module Patch Issue Queue
imageapi imageapi_540486.patch http://drupal.org/node/540486
calendar calendar-6.x-2.2-613528-5.patch http://drupal.org/node/613528
date date-6.x-2.x-549884-30.patch http://drupal.org/node/549884
views views-6.x-2.7-php53-1.patch http://drupal.org/node/452384
admin_menu 615058-adminmenu-php53-D6-1.patch http://drupal.org/node/615058
rules rules_php53fixes2.patch http://drupal.org/node/703294

Any error that looks like: unexpected $end, expecting TC_DOLLAR_CURLY or TC_QUOTED_STRING that references a .ini file can be fixed by putting quotes around the description in that file to comply with php syntax rules for .ini files.

5. Set timezone in php.ini --same process for Drupal 5 and 6

Explicitly set the timezone in php.ini by uncommenting the line that contains date.timezone and adding a zone. e.g.:
date.timezone = America/Toronto

Drupal 5

2. Modify Drupal's error reporting

See: http://funkinetics.org/klink/function-ereg-is-deprecated-error-in-drupal...

However, if you prefer to keep PHP 5.3, you can always suppress the deprecated function errors. In Drupal’s includes/common.inc, find line 590. It should be listed as:

    if ($errno & (E_ALL ^ E_NOTICE)) {

Replace this line with:

    if ($errno & (E_ALL & ~E_NOTICE & ~E_DEPRECATED)) {

This will now always suppress the Deprecated error messages.  If you have the developer tools module, you’ll need to make the same change to devel/devel.module line 460.

Note: Every time you update Drupal or the Devel module you’ll have to manually make this change until they finally  both support php 5.3.

Here is the patch that was done on Drupal 6: http://drupal.org/node/360605#comment-2047768

3. Find patches

Here is my big patch to fix everything: http://drupal.org/node/360605#comment-2273386
Other things that will need to be done in contrib:
Quotes around the description in many of the .info files including the following:
image/contrib/image_gallery/image_gallery.info
image/contrib/image_import/image_import.info
tapir/tapir.info
ubercart/uc_roles/uc_roles.info
ubercart/shipping/uc_weightquote/uc_weightquote.info
gmap/gmap_location.info
zenzen/zenzen.info
zen_basic/zen_basic.info
image/contrib/image_import/image_import.info

I have posted a patch on menu.inc here: http://drupal.org/node/744764#comment-2883022

views_rss.module needs a patch to views_rss_views_feed_argument so that the second argument is not a reference

Also Google Analytics has a line that need replacing:
-$p = module_invoke('profile', 'load_profile', $user);
+$p = call_user_func('profile_load_profile', $user);

4. Fix errors

This comment: http://drupal.org/node/514334#comment-1963440 suggests replacing ereg() with mb_ereg()
However, the official replacement is: preg_match() see: http://www.php.net/manual/en/migration53.deprecated.php
Here is some discussion on patching Drupal: http://drupal.org/node/64967
This solution would probably need a lot of work, and maintenance re-applying patches for each update of Drupal