-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add options to dump
function
#48474
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
Comments
👎🏻 Right now, some_function(
another_function(
dump(yet_another_function())
)
);
$foo = dump(fetch_data()); I would like to keep that behavior. |
Thank you very much for opening this issue @GromNaN! If that's okay, I would love to work on this and give it a try really soon, now that #48432 is being polished and finalized. Something like a first PR with the options model, and 1 or 2 options that have been mentioned in #48432. 👍 To be noted, this syntax: $options = VarDumper::options()->trace()->maxDepth(4)->toArray();
dump($var, ...$options); will only work if there are no named arguments.
|
If we are to use the The dumped variable could be the last function call. VarDumper::options()->trace()->maxDepth(4)->dump($var);
VarDumper::options()->trace()->maxDepth(4)->dd($var);
VarDumper::options()->trace()->maxDepth(4)->die()->dump($var); Brainstorming alternatives: the function could return an option builder when no argument are passed. dump()->trace()->maxDepth(4)->values($var);
dd()->trace()->maxDepth(4)->values($var); |
I really like both ideas! I am definitely convinced by the first one. The second one gives the feeling it is like a major change. Curious to hear opinions on it! |
We are adding a new behavior:
https://github.com/symfony/symfony/pull/48432/files#r1037426040 The return type will be: function dump(): mixed|VarDumperOptions |
I gave it a try. Here is a draft/WIP PR I came up with: alexandre-daubois#2 I tried an approach with options built before calling VarDumper. It uses a special named argument called public function __invoke(): Response
{
$options = (new VarDumperOptions())
->format('html')
->trace()
->traceLimit(null)
;
dump(var: 123, _options: $options);
dd(test: 'test');
throw new \LogicException('This code should never be reached!');
} |
Thank you for your feedback on my branch @GromNaN! I added a few other methods to build options, here is how this looks like now: I'm discovering a lot of features of the VarDumper while doing this. This reinforce my feeling that this feature is definitely a good idea, so everybody can easily manipulate VarDumper capabilities. |
Thank you for this suggestion. |
I guess yes! The PR is actually nearly done (a test has to be fixed). But otherwise, I think it is ready for one more review. However, I'm not 100% sure about the |
Description
Following #48432 (review)
It would be helpful to pass options to the
dump()
anddd()
functions.The underscore prefix is required to prevent conflict with named arguments that could be dynamically set.
__destruct
. So that it is more fluent.A last method can be added in case the
__destruct
would not be called (return value affected to a variable).To be complete, we need the same capability for the
dump
helper in Twig.Example
No response
The text was updated successfully, but these errors were encountered: