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 8c0df7c + d46652c commit b6d0c8c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Resources/functions/dump.php
Original file line number Diff line number Diff line change
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 b6d0c8c

Please sign in to comment.