Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable dump symfony function on production

Tags:

symfony

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

like image 924
Shay Altman Avatar asked Feb 02 '17 15:02

Shay Altman


2 Answers

You should remove the dump()s from your production code, it doesn't have to be there.

But, as noted by Cerad, since it can be annoying when you forget to remove them before checking in, you can define an empty dump() function at the begining of web/app.php:

src\web\app.php

<?php

use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;

function dump($object){
    return;
}


$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
//rest of app.php
like image 140
Veve Avatar answered Sep 27 '22 21:09

Veve


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()!

like image 44
Edmund Tam Avatar answered Sep 27 '22 23:09

Edmund Tam