How to disable dump()
function,
when its in production environment?
If i forget the dump function anywhere It crashes with an 500 error
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
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()
!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With