Changeset View
Changeset View
Standalone View
Standalone View
src/moduleutils/PhutilBootloader.php
Show First 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | private function executeInclude($path) { | ||||
// In PHP7 and later we could use error_clear_last() to clear that error, | // In PHP7 and later we could use error_clear_last() to clear that error, | ||||
// but the function does not exist in earlier versions of PHP. Instead, | // but the function does not exist in earlier versions of PHP. Instead, | ||||
// check if the value has changed. | // check if the value has changed. | ||||
// See also T12190. | // See also T12190. | ||||
$old_last = error_get_last(); | $old_last = error_get_last(); | ||||
try { | |||||
$old = error_reporting(0); | $old = error_reporting(0); | ||||
$okay = include_once $path; | $okay = include_once $path; | ||||
error_reporting($old); | error_reporting($old); | ||||
} catch (Exception $ex) { | |||||
throw $ex; | |||||
} catch (ParseError $throwable) { | |||||
// NOTE: As of PHP7, syntax errors may raise a ParseError (which is a | |||||
// Throwable, not an Exception) with a useless message (like "syntax | |||||
// error, unexpected ':'") and a trace which ends a level above this. | |||||
// Treating this object normally results in an unusable message which | |||||
// does not identify where the syntax error occurred. Converting it to | |||||
// a string and taking the first line gives us something reasonable, | |||||
// however. | |||||
$message = (string)$throwable; | |||||
$message = preg_split("/\n/", $message); | |||||
$message = reset($message); | |||||
throw new Exception($message); | |||||
} | |||||
if (!$okay) { | if (!$okay) { | ||||
throw new Exception("Source file \"{$path}\" failed to load."); | throw new Exception("Source file \"{$path}\" failed to load."); | ||||
} | } | ||||
$new_last = error_get_last(); | $new_last = error_get_last(); | ||||
if ($new_last !== null) { | if ($new_last !== null) { | ||||
if ($new_last !== $old_last) { | if ($new_last !== $old_last) { | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |