Symfony 2.3 - 自定义致命错误 [英] Symfony 2.3 - Custom Fatal Errors

查看:129
本文介绍了Symfony 2.3 - 自定义致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Symfony 2.3的问题,我无法得到它来处理致命错误的自定义函数。 Symfony异常工作正常,像404等,但是一个致命的错误不是。

I've got a problem with Symfony 2.3, I can't get it to work to get a custom function that handles the fatal errors. The Symfony exceptions work fine, like a 404 etc. but a fatal error not.

这是我在搜索互联网后,我创建了一个父控制器在TestBundle中。另一个默认控制器扩展了TestingSomeThingController。请查看下面的文件代码。但是当我删除;在DefaultController的行尾,它显示了标准的致命错误页面,而不是我放在代码中的yaay。有人有这个问题的答案吗?谢谢!

This is what I've got after searching the internet, I've a created a parent controller in the TestBundle. The other default controller extends the TestingSomeThingController. Se the files below for the code. But when I deleted the ; at the end of the line in DefaultController it's shows the standard fatal error page instead of the "yaay" I put in the code. Does anyone have got an answer for this question? Thanks!

TestingSomeThingController

<?php

namespace TestingSomeThing\TestBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller as BaseController;
use Symfony\Component\HttpFoundation\Response;

class TestingSomeThingController extends BaseController
{
    public function __construct()
    {
        set_error_handler(array($this, 'sdfg'));
        register_shutdown_function(array($this, 'sdfg'));
    }

    public function sdfg()
    {
        $error = error_get_last();
        if(isset($error)) {
            echo 'yaay';
            die();
        }
    }
}

DefaultController

DefaultController

<?php

namespace TestingSomeThing\TestBundle\Controller;

use TestingSomeThing\TestBundle\Controller\TestingSomeThingController;

class DefaultController extends TestingSomeThingController
{
    public function indexAction($name)
    {
        return $this->render('TestingSomeThingBundle:Default:index.html.twig', array('name' => $name))
    }
}


推荐答案

根据定义,一个致命的错误不可恢复。

A fatal error is by definition unrecoverable.

简单来说,这意味着没有更多的处理可以继续。

In simple terms it means that no more processing can continue.

没有办法处理它,也不应该尝试。
整点是告诉你,发生了一些致命的事情,没有更多的处理可能发生。

There is no way to handle it and nor should you want to try either. The whole point is to tell you that something fatal occurred and no more processing can take place.

fa·tal /fātl /
形容词
(1)导致死亡。
(2)导致失败或灾难。

fa·tal /ˈfātl/ Adjective (1) Causing death. (2) Leading to failure or disaster.

几乎所有的语言(包括英文)都是如此,并不是Symfony或PHP特有的东西 - 你只是不要从一些致命的东西中恢复。

This is true in almost all languages (including English) and is not something specific to Symfony or PHP - you simply don't recover from something fatal.

这篇关于Symfony 2.3 - 自定义致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆