您好我正在尝试将我的网页浏览器游戏从PHP 5.6迁移到PHP 7.0.23 现在我被困在这里,并在我的exceptionHandler函数中出错。 我使用PHP 5.6测试并且我的页面工作正常,但是当我将PHP更改为7时,它显示错误。 我查看PHP主页,没有找到任何东西,或者我可能遗漏了一些东西。
这是完整的功能:
function exceptionHandler($exception)
{
global $CONF, $USER;
if(!headers_sent()) {
if (!class_exists('HTTP', false)) {
require_once(ROOT_PATH . 'includes/classes/HTTP.class.php');
}
HTTP::sendHeader('HTTP/1.1 503 Service Unavailable');
}
if(method_exists($exception, 'getSeverity')) {
$errno = $exception->getSeverity();
} else {
$errno = E_USER_ERROR;
}
$f = fopen(ROOT_PATH.'includes/errors.txt', 'ab');
$errorType = array(
E_ERROR => 'ERROR',
E_WARNING => 'WARNING',
E_PARSE => 'PARSING ERROR',
E_NOTICE => 'NOTICE',
E_CORE_ERROR => 'CORE ERROR',
E_CORE_WARNING => 'CORE WARNING',
E_COMPILE_ERROR => 'COMPILE ERROR',
E_COMPILE_WARNING => 'COMPILE WARNING',
E_USER_ERROR => 'USER ERROR',
E_USER_WARNING => 'USER WARNING',
E_USER_NOTICE => 'USER NOTICE',
E_STRICT => 'STRICT NOTICE',
E_RECOVERABLE_ERROR => 'RECOVERABLE ERROR'
);
$VERSION = isset($CONF['VERSION']) ? $CONF['VERSION'] : 'UNKNOWN';
$DIR = MODE == 'INSTALL' ? '..' : '.';
fputs($f, '<---------------------------------------------------------------------------------------------------------------------->-['.$errorType[$errno].']-['.date('Y.m.d at (H:i:s)',TIMESTAMP).']{'.( isset($USER['id']) ? $USER['id'] : NULL ).'}
Message: '.$exception->getMessage().'
File: '.$exception->getFile().'
Line: '.$exception->getLine().'
URL: '.PROTOCOL.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].(!empty($_SERVER['QUERY_STRING']) ? '?'.$_SERVER['QUERY_STRING']: '').'
Debug Backtrace:
'.makebr(str_replace($_SERVER['DOCUMENT_ROOT'], '.',
htmlspecialchars($exception->getTraceAsString()))).'
');
echo '<!DOCTYPE html>
<head>
<title>'.(isset($CONF['game_name']) ? $CONF['game_name'].' - ' : '').$errorType[$errno].'</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="'.$DIR.'/styles/css/ingame.css">
<link rel="stylesheet" type="text/css" href="'.$DIR.'/styles/theme/gow/formate.css">
<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon">
</head>
<body id="overview" class="full">
<table width="666" style="margin-top:100px;">
<tr>
<th>Error Administration notified</th>
</tr>
<tr>
<td>
Try to reconnect to the game, or wait for error correction.
</td>
</tr>
</table>
</body>
</html>';
if($errno === 0) {
ini_set('display_errors', 0);
trigger_error("Exception: ".str_replace("<br>", "\r\n", $errstr)."\r\n\r\n".str_replace($_SERVER['DOCUMENT_ROOT'], '.', $exception->getTraceAsString()), E_USER_ERROR);
}
exit;
}
错误尝试访问其中一个页面时引发的错误:
( ! ) Fatal error: Uncaught ErrorException: Undefined offset: 8192 in C:\wamp64\www\eogame\game\includes\GeneralFunctions.php on line 892
( ! ) ErrorException: Undefined offset: 8192 in C:\wamp64\www\eogame\game\includes\GeneralFunctions.php on line 892
获得错误的行:
fputs($f, '<---------------------------------------------------------------------------------------------------------------------->-['.$errorType[$errno].']-['.date('Y.m.d at (H:i:s)',TIMESTAMP).']{'.( isset($USER['id']) ? $USER['id'] : NULL ).'}
产生错误的部分:
$errorType[$errno]
问题是在数组中还是我需要更改我的函数中更适合PHP 7的部分,也许有人可以指出我正确的方向?谢谢