Drupal Function Ereg Is Deprecated

Last modified: 
Thursday, April 16th, 2015

Ereg is Deprecated in includes/file.inc

Function ereg() is deprecated in /path/to/document/root/includes/file.inc on line 646.

This error is associated with old installations of Drupal which still include calls to the deprecated PHP ereg() family of functions. You see it a lot with Drupal 5 installations after a server has been updated to a current version of PHP. Disabling deprecation notices should be sufficient to suppress the notices.

Disable Deprecation Warnings in PHP.INI

If you have full access to the php.ini* file, you can get rid of warning messages by changing your error reporting settings there.

error_reporting  = E_ALL & ~E_DEPRECATED

*Some shared hosts allow you to make edits to your own copy of a secondary php.ini file, but I've found these rarely allow you to override the error reporting settings.

Disable Deprecation Warnings at Runtime

You can try updating the error reporting settings at runtime, but I've never known this function to work on any sort of managed or shared hosting package.

error_reporting(E_ALL & ~E_DEPRECATED);

Hack the Core!

If these solutions don't work for you, as a last resort you can hack core.

1) Open includes/file.inc

2) Jump to line 646 (or whichever line is giving you trouble).

3) Locate the call to ereg(). It might look something like this:

elseif ($depth >= $min_depth && ereg($mask, $file)) {

4) Use the old @ symbol to suppress errors on the call to ereg() like so:

elseif ($depth >= $min_depth && @ereg($mask, $file)) {

Closing Thoughts

None of these solutions fixes anything, they simply hide notices about deprecated code in your source. The ereg() function still works through to PHP 5.3, so technically your source code isn't actually broken anyway. As a rule, you really should have your public error reporting disabled on production machines, but sometimes we don't have control over that. Hacking core is seldom a great idea, but if you're still maintaining a Drupal version 4.5 or 5 site, you've gone off the map into uncharted territory as it is. Keep in mind there is no ereg() function support in PHP 6.


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.