When I call an initial new v6.14 Drupal installation on a Apache v2.2.11 and PHP 5.3.0 server
then I got the following Error/Warning (approx 20 times) in browser:

Deprecated: Function ereg() is deprecated in D:\WAMP\v2.x\www\drupal\includes\file.inc on line 902

How can I prevent this error/warning?



ergophobe’s picture

The warning itself is not a problem and I'm sure it will be fixed, as the drupal project as has committed to being fully PHP5 compliant. ereg() is deprecated as of PHP 5.30, but it is still allowed, so it's not a problem yet (it will be for PHP6).

See: http://www.php.net/manual/en/function.ereg.php

So the problem is not the warning, but the reporting of it.

On a production system, you should suppress error reporting to the browser and only log errors (see below). So that right there will stop it from annoying the user.

Also, you can turn down error reporting to not report warnings. PHP 5.3 adds a new error reporting level E_DEPRECATED. So you would want to turn that off. Your reporting might look like this:

You can change this in several contexts.

If you have no other option
- at runtime (in your index.php file): error_reporting(E_ALL ^ E_DEPRECATED); // report all except deprecated

- in php.ini file if you have control of this (the way my server is set up, this is the only method I can use - everything will crash if I do it via .htaccess)

error_reporting  =  E_ALL & ~E_DEPRECATED
display_errors = Off
log_errors = On  

YOu can also change this in your .htaccess if you don't have access to php.ini, but you can't use the constants but have to convert them to integers. The value of E_ALL and has changed in 5.30 and will change again, so I would just put this in my .htaccess and be done with it:

php_value 1
php_flag display_errors off
php_flag log_errors on

That will report errors only and will not display them to the screen, but only to the logs. If you run phpinfo() you can find out where your error logs are located. To do that, just create a file called something-obscure.php, put put in just one line


and put it in your root directory. Then just go to http://something-obscure.php and you'll get all sorts of output.

manicolaus’s picture

Putting the code suggested above into the .htaccess file only caused another error message, in huge type, "Server error" etc and program lockup. Maybe there's a special place in the .htaccess where this needs to go. In any event, it didn't work for me. What worked was to downgrade from PHP 5.3 to 5.211. With WAMPServer running on localhost that's very easy to do. After that, the error message went away. It would be better, though, if the code in files.inc were updated, at least in the 6.x dev version.

ergophobe’s picture

No it depends on your setup and how you're running PHP

On my current server, for example, putting it in the .htaccess will cause a server error and you MUST put it in the php.ini file.

On my old server, I only had access to .htaccess and couldn't put anything in the php.ini

Ask your host about editing your php.ini

aa-tools’s picture

If you run 5.3.0 as the latest PHP version:

- open the file includes/file.inc
- in line 902, replace
elseif ($depth >= $min_depth && ereg($mask, $file)) {
elseif ($depth >= $min_depth && mb_ereg($mask, $file)) {
- save the file
- set permissions for .sites/default/settings.php to 777
- set permissions for directory .sites/default/files to 777
- restart the installation and follow instructions

You should be able to run the drupal installation in latest PHP version then.

jaramillo’s picture

yay, that fixed it.

ergophobe’s picture

The problem with that solution is that you will have to remember to do it every time you do a security update to drupal core (until it gets fixed in core, which may already be the case).

I always avoid hacks to core if at all possible.

amittripathi2k2’s picture

I had this issue and your advise helped me in just one sec.

I really had to comment back so I created account, logged in and replying you with all appreciation I can.

Thanks again. Keep up good work.

kremisoski’s picture

Alternatively if you add just 2 lines to your default .htaccess file inside drupal after line 58:

php_flag display_errors off
php_flag log_errors on

You should not have any more troubles. Make sure this is within <IfModule mod_php5.c>

Make sure you do not add php_value 1 in here though as this will most likely result in an internal server error...