本文整理匯總了PHP中LogicException::getMessage方法的典型用法代碼示例。如果您正苦於以下問題:PHP LogicException::getMessage方法的具體用法?PHP LogicException::getMessage怎麽用?PHP LogicException::getMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類LogicException
的用法示例。
在下文中一共展示了LogicException::getMessage方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: handler
/**
* 顯示exception錯誤信息
* @param LogicException $e
*/
function handler($e)
{
if ($e->getCode() == 404 && !DEBUG) {
header("HTTP/1.0 404 Not Found");
exit;
}
// 正式情況下
$this->out['_msg'] = $e->getMessage();
$this->out['_code'] = $e->getCode();
// 隻有LogicException才需要顯示詳細,記錄日誌
if ($e instanceof LogicException) {
// DEBUG時顯示調試詳細信息
if (DEBUG) {
$this->out['_exception_detail']['trace'] = $this->getTraceDesc($e->getTrace());
$this->out['_exception_detail']['file'] = $e->getFile();
$this->out['_exception_detail']['line'] = $e->getLine();
} else {
$this->out['_msg'] = '係統錯誤';
}
}
if (!$this->tpl) {
$this->tpl = PATH_APP . '/template/msg.tpl';
}
$this->display();
}
示例2: __toString
/**
* Magic method implementation of the above (for PHP >= 5.2.0), so we can do, eg:
* $foo = new Message( $key );
* $string = "<abbr>$foo</abbr>";
*
* @since 1.18
*
* @return string
*/
public function __toString()
{
if ($this->format !== 'parse') {
$ex = new LogicException(__METHOD__ . ' using implicit format: ' . $this->format);
\MediaWiki\Logger\LoggerFactory::getInstance('message-format')->warning($ex->getMessage(), ['exception' => $ex, 'format' => $this->format, 'key' => $this->key]);
}
// PHP doesn't allow __toString to throw exceptions and will
// trigger a fatal error if it does. So, catch any exceptions.
try {
return $this->toString();
} catch (Exception $ex) {
try {
trigger_error("Exception caught in " . __METHOD__ . " (message " . $this->key . "): " . $ex, E_USER_WARNING);
} catch (Exception $ex) {
// Doh! Cause a fatal error after all?
}
if ($this->format === 'plain' || $this->format === 'text') {
return '<' . $this->key . '>';
}
return '<' . htmlspecialchars($this->key) . '>';
}
}