Anyone know offhand a line of code to trip STRICT and DEPRECATED errors?

I am testing this error handler.

	public static function error( $code, $message, $file, $line, $context ) {
		if ($code | (E_ALL - (E_NOTICE + E_WARNING + E_USER_NOTICE + E_USER_WARNING )) ) {
			 * This goes to the javascript console, and arrays are pretty ugly
			 * when displayed there because of prototype.js extendsions to array.
			Core::$errorLog[] = (object) array(
				'number' => $code,
				'string' => $message,
				'file' => $file,
				'line' => $line,
				'context' => (object) $context,
				'trace' => (object) debug_backtrace()
			// We've handled this error.
			return true;
		} else { // Throw fatal Exception.
			// Not written yet.

I want it to catch E_DEPRECATED and E_STRICT as well. The code catches non-fatal errors and stores a detailed report for each one, then embeds the results in the output html so javascript can display it in the Firebug console, or similar action (for a javascript output file the errors are logged in a comment text block at the start of the file, if image output is being done a log file is written and so on).

@Scallio - Not my area of expertise but I’ll give it a try.


$deprecated = & new stdClass; // Crashed completely.
$strict     = mktime(); // Was not caught.

Looks like I’ve work to do.

BTW, is there a function that returns the error name for the code? e.g. 2048 = “E_STRICT”

K, got it resolved. Final detection line.


Reason is that DEPRECATED and STRICT are not included in E_ALL. To catch them I use

error_reporting( -1);

In that case I’ll just make them constants for the Framework’s root exception class.

Not one built-in to PHP, it’s pretty basic to write one yourself.

$deprecated = & new stdClass;
$strict     = mktime();

Don’t you mean the following?


Bit wise operators are way faster for this kind of thing than traditional addition and subtraction. Also you want to do $code & (etc) instead of $code | (etc) since the latter doesn’t make sense …