Skip to content Skip to navigation

Drupal and PHP 5.3

Posted by: 

jump to:

Overview

The www.stanford.edu servers were upgraded in early January, 2012, with a new version of their operating system (Debian Squeeze). For the most part this should not affect sites on the server; however, an update to PHP 5.3 has the potential to cause problems with outdated Drupal installs, particularly those earlier than Drupal 6.16.

Common Problems

screenshot showing multiple PHP error messages indicating that ereg() is a deprecated function on line 649 of file.inc

Function ereg() is deprecated on line 649 of includes/file.inc. You may see a lot of these messages.

screenshot showing fatal PHP error indicating that the function date_diff() cannot be redeclared on line 767 of date_api.module

PHP error indicating that the function date_diff() cannot be redeclared on line 767 of date_api.module

screenshot showing a premature end of script headers server error

"Premature end of script headers" server error

The Fix(es)

If anything is broken, try the following steps (in recommended order, from less to more extreme)

  1. Update Drupal core and contributed modules to the latest stable versions (5.23 for Drupal 5, 6.22 for Drupal 6).
  2. Go to admin/settings/error-reporting and change the "Error reporting" setting to "Write errors to the log". This will stop the Drupal error messages from appearing on your site.
    screenshot of the error reporting setting set to write errors to the log
    Or, for the drush-inclined:
    drush vset error_level 0
  3. The "Premature end of script headers" error is caused by using a custom php.ini file in your install directory. You can resolve it by adding the following line to your php.ini:
    cgi.force_redirect = 0
  4. The "Function ereg() is deprecated..." error (Drupal 5): find the line in includes/file.inc indicated by the error message, comment it out, and replace it, like so:
     647         //elseif ($depth >= $min_depth && ereg($mask, $file)) {
     648         elseif ($depth >= $min_depth && preg_match("/$mask/", $file)) {
  5. A "Parameter 1 to theme_field() expected to be a reference, value given in /path/to/drupal/includes/theme.inc on line 172." error message (Drupal 5): find the line in includes/theme.inc indicated by the error message, comment it out, and replace it, like so:
     172     //$output = call_user_func_array($functions[$function], $args);
     173     $output = call_user_func_array($functions[$function], &$args);

If you continue to have difficulties after performing the above steps, you can ask for help on the drupallers list: drupallers@lists.stanford.edu.

As always, when updating Drupal core or contributed modules, follow best practices, including having a current backup, and testing on a development copy of your site if possible. Instructions on how to restore your Drupal site from a backup are available at http://techcommons.stanford.edu/topics/drupal/restore-drupal-backup.