-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[VarDumper] Make dump()
a little bit more easier to use
#24280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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. ```php dump($object)->method(); ```
dump()
a little bit more easier to usedump()
a little bit more easier to use
I wanted that yesterday, so definitely yes :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice change! @freekmurze thanks (and congrats!) for your first contribution to Symfony!! 🎉
This is wrong, because if I do a |
@Taluu in that case the last argument is the var that is returned ;) dump($string, $float, $object)->method(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
Which means it is even less obvious than you think it was... maybe return |
That's the same thing (I read too fast), but still. If I am using This is making something fluent just for the sake of making it fluent : https://ocramius.github.io/blog/fluent-interfaces-are-evil/ |
This is just about easing inspecting some vars when developing. It's not just for the sake of making it fluent. Thanks to this, you just have to wrap a variable or an expression instead of writing a new line and possibly executing the same piece of code twice.
Returning |
For the Something that would be more convenient IMO would be to |
But what would be the usefulness of this in practice, appart from the debatable less arbitrary nature of the returned value? How would it be convenient? It'll return a generator and won't allow chaining, so again defeats the purpose of this PR. |
When you dump multiple values, you're probably not using them inline anyways, so the benefit of simply adding and removing |
I wrote "in that case", meaning when you pass multiple vars. |
Don't forget that the goal of this PR is it so make We can accept that this PR is a first step, and create new PRs later to improve the behavior of what's returned in the case of multiple arguments ? |
@greg0ire you cannot make a function become a generator conditionally, as this is determined at compile time (based on the presence of a |
TIL 💡 , but I think you meant to answer to @Taluu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very useful for people who hate one-time variables like I do
We can have it return the exact same list of things of course.. if ($moreVars) {
return func_get_args();
}
return $var; and then we could do both dump($stuff)->someMethod(); and: $object->someMethod(...dump($arg1, $arg2, $arg3)); imho: it would be a bit awkward to do
The goal is to dump some variables and make your application still work, kind of, without having to do too many keystrokes. |
I really like what @hannesvdvreken proposed. I'll update this PR. |
That's exactly what I proposed BTW :P Although I didn't think about the unpacking at the time, good thinking @hannesvdvreken ! |
Thank you @freekmurze. |
…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
Hello. I think this is a BC break. Now we can not die(dump()) Anymore.
|
Oh true. Before it would return null, and thus you would exit (or die) with null This will require a small change to At least you won't run |
Yeah I know why it is not working anymore ;) |
where can we read more about that? |
dump() is not covered by the BC policy, it's not part of any "API", it's just a temporary helper. |
It's a shame. This PR has broken the dump function since it both outputs and returns now. This whole functionality should have been on a different function or something. R.I.P. dump() |
Imagine you have this code:
If you want to dump the object, this is currently the way to do that:
This PR makes adding (and removing) the
dump
function easier. When using one argument is used, that argument is returned.When dumping multiple things, they all get returned. So you can to this: