Skip to content

Commit

Permalink
feature #28317 [VarDumper] Allow dd() to be called without arguments …
Browse files Browse the repository at this point in the history
…(SjorsO)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[VarDumper] Allow dd() to be called without arguments

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

**Description**
A while back the `dd()` helper was [added to the VarDumper component](#26970) which was (i think) inspired by Laravel's `dd()` helper. Laravel has [removed their version of the helper](laravel/framework#25087) in favor of the helper in Symfony.

However, as opposed to the Laravel helper, the Symfony helper requires at least one argument. Calling the Laravel helper with no arguments simply killed the program (and usually showed a white screen), calling the Symfony helper with no arguments throws a `TypeError: Too few arguments to function dd()` exception (which gets rendered by the error handler and fills the whole screen with useless information).

Being able to call the `dd()` helper with no arguments is useful because it is a quick way to tell you if your code reaches a certain point. If it does, you can fill in the `dd()` with variables to keep debugging.

This PR allows the dd helper to be called without arguments.

This PR also makes the helper call `die` instead of `exit` to better reflect the function name 😄

Commits
-------

a73dfad [VarDumper] Allow dd() to be called without arguments
  • Loading branch information
nicolas-grekas committed Sep 21, 2018
2 parents ea2a65c + a73dfad commit 6856c02
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/Symfony/Component/VarDumper/Resources/functions/dump.php
Expand Up @@ -32,14 +32,12 @@ function dump($var, ...$moreVars)
}

if (!function_exists('dd')) {
function dd($var, ...$moreVars)
function dd(...$vars)
{
VarDumper::dump($var);

foreach ($moreVars as $v) {
foreach ($vars as $v) {
VarDumper::dump($v);
}

exit(1);
die(1);
}
}

0 comments on commit 6856c02

Please sign in to comment.