8000 feature #28317 [VarDumper] Allow dd() to be called without arguments … · symfony/symfony@6856c02 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6856c02

Browse files
feature #28317 [VarDumper] Allow dd() to be called without arguments (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
2 parents ea2a65c + a73dfad commit 6856c02

File tree

1 file changed

+3
-5
lines changed
  • src/Symfony/Component/VarDumper/Resources/functions

1 file changed

+3
-5
lines changed

src/Symfony/Component/VarDumper/Resources/functions/dump.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ function dump($var, ...$moreVars)
3232
}
3333

3434
if (!function_exists('dd')) {
35-
function dd($var, ...$moreVars)
35+
function dd(...$vars)
3636
{
37-
VarDumper::dump($var);
38-
39-
foreach ($moreVars as $v) {
37+
foreach ($vars as $v) {
4038
VarDumper::dump($v);
4139
}
4240

43-
exit(1);
41+
die(1);
4442
}
4543
}

0 commit comments

Comments
 (0)
0