Depecriated Errors - Cannot Hide

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Depecriated Errors - Cannot Hide

Post by Benjamin »

I'm trying to get some depreciated errors to disappear. Am I missing something or is this a bug in php 5.3.2?

Code: Select all

<?php
error_reporting(0);
ini_set('display_errors', "false");

set_error_handler('an_error_handler');

function an_error_handler($level, $message, $file, $line) {
    switch ($level) {
        case 2:         $level = 'E_WARNING';           break;
        case 8:         $level = 'E_NOTICE';            break;
        case 256:       $level = 'E_USER_ERROR';        break;
        case 512:       $level = 'E_USER_WARNING';      break;
        case 1024:      $level = 'E_USER_NOTICE';       break;
        case 6143:      $level = 'E_ALL';               break;
        case 2048:      $level = 'E_STRICT';            break;
        case 4096:      $level = 'E_RECOVERABLE_ERROR'; break;
        case 8192:      $level = 'E_DEPRECATED';        break;
        case 16384:     $level = 'E_USER_DEPRECATED';   break;
        default:        $level = "UNKNOWN ERROR $level";
    }

    $message = "$message in \"$file\" line $line";

    #echo '<div style="font-family: sans-serif; font-size: 12px; border-width: 1px; border-style: solid; border-color: #ff0000; background-color: #ffffff; color: #000000; padding: 3px; margin: 3px;">' . $message . '</div>';

    return true;
}

class foo {

}

$foo =& new foo();
[text]Deprecated: Assigning the return value of new by reference is deprecated[/text]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Depecriated Errors - Cannot Hide

Post by John Cartwright »

I don't get any notices in 5.3.1, so I'm not sure. Although, as you probably know, objects are automatically passed by reference.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Depecriated Errors - Cannot Hide

Post by twinedev »

Are you by chance trying to run Joomla on a 5.3 machine? We had a client moved to our hosting, and man oh man, every page load products about (no joke here) 2,000 lines of that crap!!! Even going in through joomla's settings and changing the error reporting still have us about 14 per call. (I even did a fresh install to see if it was some module he had installed, nope, "out of the box" within 10 minutes had a 20meg error log.

In the end we moved it over to our PHP 4 legacy server. One of our guys tried to work with it going through and changing all calls to be by reference (adding &), but 1. there are so many places, and 2, who knows when a function that is intended to act on a local copy will change something that affects the class elsewhere.

Client was soon switching to out CMS we use, so temp housing on the legacy server was good enough. But I did a lot of searching and didn't find how to squash those messages easily.

-Greg
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Depecriated Errors - Cannot Hide

Post by Benjamin »

No, this for a script which is sold and still supports PHP 4. The issue here is that PHP is being instructed to not display errors however it is still displaying depreciated errors. I've tried pretty much everything except editing php.ini because I shouldn't have to change php.ini to make these go away.

In fact, the errors still display even if the line in question isn't even executed. The only way I was able to get rid of them was by testing the version and then using eval 8O

Code: Select all

        if (version_compare(PHP_VERSION, '5.0.0', '<')) {
            eval('$instances[$class] =& new $class;');
        } else {
            $instances[$class] = new $class;
        }
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Depecriated Errors - Cannot Hide

Post by Benjamin »

John Cartwright wrote:I don't get any notices in 5.3.1, so I'm not sure. Although, as you probably know, objects are automatically passed by reference.
Are they turned off in php.ini? If so give it a go with then enabled and see what happens. This may be a new issue with 5.3.2 though.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Depecriated Errors - Cannot Hide

Post by requinix »

This particular error is a compile-time error, not runtime. Changing error_reporting or display_errors inside the file won't work - you have to do sometime before the file gets included (or in php.ini).
Post Reply