Skip to content

Commit

Permalink
feature #24280 [VarDumper] Make dump() a little bit more easier to …
Browse files Browse the repository at this point in the history
…use (freekmurze)

This PR was submitted for the master branch but it was squashed and merged into the 3.4 branch instead (closes #24280).

Discussion
----------

[VarDumper] Make `dump()` a little bit more easier to use

| Q             | A
| ------------- | ---
| Branch?       |  3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes

Imagine you have this code:

```php
$object->method();
```

If you want to dump the object, this is currently the way to do that:

```php
dump($object);

$object->method();
```

This PR makes adding (and removing) the `dump` function easier. When using one argument is used, that argument is returned.

```php
dump($object)->method();
```

When dumping multiple things, they all get returned. So you can to this:

```php
$object->someMethod(...dump($arg1, $arg2, $arg3));
```

Commits
-------

42f0984 [VarDumper] Make `dump()` a little bit more easier to use
  • Loading branch information
nicolas-grekas committed Sep 23, 2017
2 parents 0a9d46d + 42f0984 commit e84d2d0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Symfony/Component/VarDumper/Resources/functions/dump.php
Expand Up @@ -20,5 +20,11 @@ function dump($var)
foreach (func_get_args() as $var) {
VarDumper::dump($var);
}

if (1 < func_num_args()) {
return func_get_args();
}

return $var;
}
}

0 comments on commit e84d2d0

Please sign in to comment.