Function ereg() is deprecated Error in Drupal 6.x with PHP 5.3

If you updated your PHP to 5.3 and you run Drupal 6.x you will notice that you get some odd errors like:

    Function ereg() is deprecated in…

This is not a Drupal issue as it is noted by the Drupal site that it does not yet support PHP 5.3 and there have been new error flags added to PHP.   One solution is revert back to PHP 5.2.x. As I am unsure of other conflicts with Drupal and PHP 5.3, this is probably the best bet for a dedicated production system that does not specifically need PHP 5.3.

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.

19 comments to Function ereg() is deprecated Error in Drupal 6.x with PHP 5.3

  • Adam Bolton

    Hi,

    thanks for this tip – has taken off all of the annoying error messages for me :)

  • Rhinceros_Pultin

    Thank you very much. Now it is running smoothly.

  • Leo

    Thanks mate for posting this!

    It makes more sense to change the if condition than to re-install lower php

    Thanks a lot…

    • On thing I’d be careful of is if you’re running a production system. The deprecated function error flag may be only the tip of the iceberg in regards to what else is incompatible with Drupal in PHP 5.3. If it’s for personal use or development, I’m always ready to move onto the newest official release, but I’d wait until I got the blessings from Drupal before upgrading any business related servers. It’s not only the Drupal but the army of modules that may be problematic…

  • Kaido

    Thanks.. Its super.. My server runs much faster than with older PHP version and there is no error ;) )

    • Yeah, one of the advantages, if you’re willing to risk going to 5.3 is a modest performance boost.

      • For now I have to take my words back.. This doesn´t work so well.. There some modules with will not work … :(

        • This is the sort of can of worms I’d want to avoid for any system I didn’t have a few day’s to ‘patch’ modules to get them to work. I’m figuring 6 months or so before Drupal is up to speed and about that for the major modules–if they ever plan to deal with it for anything before Drupal 7. Less used modules will probably never get updated to work with php 5.3.

  • Murali

    Modified as per the instruction, and restarted the lampp, Still the same error.
    Could not install on ubuntu using xampp 1.7.2
    Any idea what could be the reason

    :-(

  • Hi…

    Thanks for this solutions. I do a post un my blog with this information, but in spanish.

    If do you like see it, the post is the next: http://www.undomain.es/node/297

    thanks a lot for all.

    Regards from spain :)

  • I had the same problem and hope in the further Versions this problem will be solved. Now the tip is working, Thanks!

  • James Shimota

    as of the 6.14 drupal release, the original common.inc file has this on line 670 as:
    if ($errno & (E_ALL ^ E_NOTICE ^ E_DEPRECATED)) {

    yet the e_deprecated error still appears. I interpret that poorly but I still get the error.

    • Both should work. Let’s look at why they should work. The “^” is the “exclusive or” operator. Here are the binary values of each of the error flags (see http://us.php.net/manual/en/errorfunc.constants.php):

      111011111111111 (E_ALL)
      000000000001000 (E_NOTICE)
      010000000000000 (E_DEPRECATED)

      Each of the bits in the binary is field that gets reported. In a basic php program, if your php.ini was set to report just E_ALL, every error except E_STRICT (notice the one bit set to ’0′ in E_ALL) should get reported. To turn off errors, you ‘flip’ it’s bit to 0. When you exclusive or numbers together, if any odd number of bits is set to ’1′ across the numbers, the result is set to ’1′, if not it is ’0′ . Simple the below Examples:

      001 ^ 010 = 011
      100 ^ 000 = 100
      111 ^ 111 = 000
      000 ^ 000 = 000
      111 ^ 001 = 110
      etc…

      With 3 numbers the same logic carries, but just like math you need to process it from left to right:
      001 ^ 000 ^ 000 = 001
      001 ^ 001 ^ 000 = 000
      001 ^ 001 ^ 001 = 001 (Notice! the first two 001 cancel out to make 000 which is XOR’d with 001, resulting in 001).

      Thus, E_ALL ^ E_NOTICE = 111011111111111 ^ 000000000001000 = 111011111110111
      and this XOR’d with E_DEPRECATED should be:
      111011111110111 ^ 010000000000000 = 101011111110111 = #AFFF7

      Now, my head hurts when I have to XOR more than 2 numbers, so my version uses similar logic, but with NOT’d (~) flag values and using ANDs. NOTing a binary just reverses the bits of the number.
      111011111111111 (E_ALL)
      111111111110111 (~E_NOTICE)
      101111111111111 (~E_DEPRECATED)

      Strait ANDing is simple, just keep only the bit fields that are set to ’1′ in all the values. This means:
      111011111111111 & 111111111110111 & 101111111111111 = 101011111110111 =#AFFF7

      So, to end a long story, I have no clue why it’s still appearing in Drupal 6.14 if indeed they use E_ALL ^ E_NOTICE ^ E_DEPRECATED. My mostest bestest guestimate is check to see if you’re using the developer tools module (as noted in the post) or some other module that overrides the error settings.

      Good luck and let me know what you find out!

    • I just downloaded and installed 6.14 and it works without the deprecated errors.

  • Mike

    I think the better solution is to change the php.ini file. I used “Easy PHP” on my Windows system, and it comes set up for Development. However, if you change it to match what the comments call the “Production” value, you can run install.php for Drupal:

    ; Development Value: E_ALL | E_STRICT
    ; Production Value: E_ALL & ~E_DEPRECATED
    ; http://php.net/error-reporting
    ; error_reporting = E_ALL
    error_reporting = E_ALL & ~E_DEPRECATE

    • On a personal system where you have 100% control, editing the php.ini is definitely the easiest thing to do. However, if you are on a shared hosting system (where you can’t edit the php.ini) or have multiple sites with differing error reporting needs, it’s best to control error reporting in the application (and it may be your only option in some cases).

  • My solution was to change the function ereg() to preg_match()

    # in includes/file.inc line 911
    elseif ($depth >= $min_depth && preg_match(“/”.$mask.”/”, $file)) {

    Do not draw the correct error messages.
    The development server should be with the value
    E_ALL | E_STRICT

  • hey,
    thank you but i cant find the directory of the includes/common.inc
    can u tell where to find the right folders??

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>