debug($text, $level); } /** * Global shortcut for $it_debug::intermal_error() * @see it_debug */ function internal_error($text) { if (isset($GLOBALS['it_debug'])) $GLOBALS['it_debug']->internal_error($text); else exit; /* NOT REACHED */ } /** * Convert a htmlentities-encoded string back to normal */ function it_htmlentities_decode($string) { return strtr($string, array_flip(get_html_translation_table(HTML_ENTITIES))); } /** * Clone an object and return copy, works for all PHP versions */ function &it_clone(&$object) { $result = (is_object($object) && version_compare(zend_version(), 2, '>=')) ? clone($object) : $object; return $result; # PHP internals need a tmp var to return by ref } /** * Defines a new error_handler which gives a Stacktrace * To activate, use: set_error_handler('it_error_handler'); */ function it_error_handler($errno, $errstr, $errfile, $errline) { $errors = array( 1 => 'ERROR', 2 => 'WARNING', 4 => 'PARSE', 8 => 'NOTICE', 16 => 'CORE_ERROR', 32 => 'CORE_WARNING', 64 => 'COMPILE_ERROR', 128 => 'COMPILE_WARNING', 256 => 'USER_ERROR', 512 => 'USER_WARNING', 1024 => 'USER_NOTICE', 2048 => 'STRICT', ); $error = isset($errors[$errno]) ? $errors[$errno] : $errno; if (ini_get('display_errors') && ($errno & ini_get('error_reporting'))) { $stack = debug_backtrace(); array_shift($stack); $url = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; $ref = $_SERVER['HTTP_REFERER']; $errfile = preg_replace('#^/data./www/#', '/www/', $errfile); foreach ($stack as $level) { if (isset($level['class'])) $level['function'] = "{$level['class']}->{$level['function']}"; $file = preg_replace('#^/data./www/#', '/www/', $level['file']); $args = array(); foreach ((array)$level['args'] as $arg) { switch (gettype($arg)) { case 'array': $args[] = 'Array[' . count($arg) . ']'; break; case 'object': $args[] = 'Object:' . get_class($arg); break; case 'boolean': $args[] = $arg ? 'true' : 'false'; break; default: $args[] = '"' . (string)$arg . '"'; break; } } if ($levelnum++ == 0) $message .= "Line {$level['line']} $file # $error: $errstr\n"; else $message .= "Line {$level['line']} $file # {$level['function']}(" . join(', ', $args) . ")\n"; } if ($_SERVER['HTTP_HOST']) { foreach((array)$_COOKIE as $key => $val) $cookies .= "$key=$val "; error_log("$error: $errstr at Line $errline $errfile url=$url ref=$ref $cookies"); echo "\n\n
\n$message