Empty dump() output in Symfony CLI Empty dump() output in Symfony CLI symfony symfony

Empty dump() output in Symfony CLI


For some reason, it looks like what you are trying to do is actually dependency injecting a specific handler into VarDumper

So the condition null === self::$handler is always false in the below reproduced snippet of that class code, and, thus, the dumper you expect for 'cli' === PHP_SAPI is not set.

public static function dump($var){    if (null === self::$handler) {    /**       ^--- this one       **/        $cloner = new VarCloner();        $dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();        self::$handler = function ($var) use ($cloner, $dumper) {            $dumper->dump($cloner->cloneVar($var));        };    }    return call_user_func(self::$handler, $var);}

source: Symfony/Component/VarDumper/VarDumper.php

Now, knowing this, your solution is as easy as just setting the handler of VarDumper back to null

Working code:

# bin/app_dev_cli.php<?phpuse Symfony\Component\VarDumper\VarDumper;require __DIR__.'/../app/autoload.php';$kernel = new AppKernel('dev', true);$kernel->boot();/** This line (plus the use statement on top) does what you want **/VarDumper::setHandler(null);// Useful global vars$container = $kernel->getContainer();$doctrine = $container->get('doctrine');$em = $doctrine->getManager();

When run:

$ php -aInteractive shellphp > require 'bin/app_dev_cli.php';# bin/app_dev_cli.php php > dump('hi'); "hi"