Sunday, June 12, 2011

Function ereg() is deprecated

I have been working with my Drupal site for slightly over a month now, and I have seen various warnings appear on different screens.  These warnings did not affect the site so I did not dedicate much time to resolving these issues.  Today I finally felt the urge to resolve these issues.  The number of messages that Drupal must process and display on the page greatly increased the time required to display the page.  I can reproduce the issue by going to logging in as administrator and going to Administer, then Site Building, and then Modules.

I decided to focus on the warning Function ereg() is deprecated in /var/www/site/includes/ on line 895 because this particular warning appeared more times than any other.  A page dedicated to this warning can be found on Drupal's site.  The comments on this page suggest many possible resolutions.  One solution suggested modifying line 895 of file/var/www/site/includes/ (the offending line mentioned by the error message).

The solution suggested adding an '@' before the function call ereg() (the function call mentioned by the error message.  I had never heard of this operator before, so I did a little research.  I finally found the this page on which explains that when an '@' symbol is "prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored."  I made the required modification and the warning disappeared.

I wouldn't really call this a fix because this does not solve the underlying issue; it is a band-aid.  So what is the underlying issue?  The function ereg() is deprecated in php 5.3 according to this page on, and the function preg_match(), which is faster and uses a Perl-compatible regular expression syntax, should be used instead.

According to a comment by VM on Drupal's site, Drupal 6 does not support PHP 5.3 until Drupal version 6.14.  The ideal solution to this problem (and probably every other warning I see) is to upgrade from Drupal version 6.9 to 6.14 (or higher).  I read an article on Drupal's site on upgrading which involved backing up my site and it sounded like quite a bit of work.  I felt this would be a good article for another post on another day.  So I decided to go the route of adding '@' before the function call to suppress the error messages.

Thanks for reading.


  1. For what it's worth, the post-6.14 versions still prompt the "deprecated" error. The issue with switching to preg_match was that it treats its inputs differently from ereg, and would therefore be considered a change to the API - see this post in the core issue: "drupal_system_listing() and file_scan_directory() expose their ereg regex, this means that it will break every module which uses this function, for example SimpleTest."

    The "band-aid" solution is appropriate in this instance because Drupal 6 is no longer the "current" version of the software; it's being maintained and supported but there's not going to be any new development.

    All of that said - you really should keep your site up to date with the latest 6.x releases. Some of them include important security fixes. By not upgrading you're leaving your site potentially open to hacks and/or abuse. Backing up is a hassle, yes, but really you should be backing up your data regularly anyway...

  2. Hi!
    I am a newbie, but I tried mb_ereg() insted of ereg() and my PHP pages work. Will this work around be valid once hosting servers upgrade to later versions of PHP??