How to disable dump symfony function on production

后端 未结 5 976
青春惊慌失措
青春惊慌失措 2021-01-02 20:03

How to disable dump() function, when its in production environment? If i forget the dump function anywhere It crashes with an 500 error

5条回答
  •  既然无缘
    2021-01-02 20:40

    For Symfony 4.1+, you can modify index.php this way:

      if ($debug) {
         umask(0000);
    
         Debug::enable();
    + } else {
    +     \Symfony\Component\VarDumper\VarDumper::setHandler(function($var) {});
    + }
    

    Then dump() will do nothing when called. If you want you can throw an Exception or write some log.

    The problem is that the content of dump() will go to the web debug toolbar in dev mode, which can be easily overlooked. When deploying such code to production, user will then see an inline dump()!

提交回复
热议问题