Hello i am trying to migrate my web browser game from PHP 5.6 to PHP 7.0.23.
Now i am stuck here and get errors in my exceptionHandler function.
I tested with PHP 5.6 and my page works, but when i change PHP to 7 it displays error.
I look in PHP homepage and did not find anything or i probably missing something.
This is the full Function:
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;
}
Error what is thrown when trying to access one of the pages:
( ! ) 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
The line that gets error:
fputs($f, '<---------------------------------------------------------------------------------------------------------------------->-['.$errorType[$errno].']-['.date('Y.m.d at (H:i:s)',TIMESTAMP).']{'.( isset($USER['id']) ? $USER['id'] : NULL ).'}
Part that makes error:
$errorType[$errno]
Are the problem is in array or i need to change parts of my function that better suits PHP 7, maybe someone can point me in right direction? Thanks