Skip to content

Instantly share code, notes, and snippets.

@chrisliuqq
Last active October 4, 2017 11:15
Show Gist options
  • Save chrisliuqq/96de1ef8160a1d41b6af315c6fb611f3 to your computer and use it in GitHub Desktop.
Save chrisliuqq/96de1ef8160a1d41b6af315c6fb611f3 to your computer and use it in GitHub Desktop.
[PHP] Laravel: override the dd helper function

bootstrap/app.php

+require_once __DIR__.'/../app/helpers.php';
require_once __DIR__.'/../vendor/autoload.php';

app/helpers.php

<?php

use Illuminate\Support\Debug\Dumper;

if (!function_exists('dd')) {
    /**
     * Dump the passed variables and end the script.
     *
     * @param  mixed
     */
    function dd()
    {
        list($callee) = debug_backtrace();

        printf('<legend>File: %s : %s</legend>', $callee['file'], $callee['line']);

        array_map(function ($x) {
            (new Dumper())->dump($x);
        }, func_get_args());

        die(1);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment