* Callback used as a registered shutdown function.
*
* This is used as callback from the interpreter at system shutdown.
* If the last error was not a recoverable error that we already reported,
* and log as fatal exception.
*
* Special handling is included for missing class errors as they may
* indicate that the user needs to install 3rd-party libraries via
* Composer or other means.
*
* @since 1.25
* @return bool Always returns false
*/
publicstaticfunctionhandleFatalError(){
// Free reserved memory so that we have space to process OOM
// errors
self::$reservedMemory=null;
$lastError=error_get_last();
if($lastError===null){
returnfalse;
}
$level=$lastError['type'];
$message=$lastError['message'];
$file=$lastError['file'];
$line=$lastError['line'];
if(!in_array($level,self::FATAL_ERROR_TYPES)){
// Only interested in fatal errors, others should have been
// handled by MWExceptionHandler::handleError
returnfalse;
}
$msgParts=[
'[{reqId}] {exception_url} PHP Fatal Error',
($line||$file)?' from':'',
$line?" line $line":'',
($line&&$file)?' of':'',
$file?" $file":'',
": $message",
];
$msg=implode('',$msgParts);
// Look at message to see if this is a class not found failure (Class 'foo' not found)
if(preg_match("/Class '\w+' not found/",$message)){
// phpcs:disable Generic.Files.LineLength
$msg=<<<TXT
{$msg}
MediaWiki or an installed extension requires this class but it is not embedded directly in MediaWiki's git repository and must be installed separately by the end user.
Please see <a href="https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries">mediawiki.org</a> for help on installing the required components.