Skip to content
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

Add variable name dumped to the `dump` result #30250

Closed
ismail1432 opened this Issue Feb 15, 2019 · 7 comments

Comments

Projects
None yet
6 participants
@ismail1432
Copy link
Contributor

commented Feb 15, 2019

Description
I know that it can be done with X-debug or other tools but it will also good if the VarDumper can also provide the original $var name.

Example

$message = 'Symfony is awesome';
$admin = (new User());
dd($message, $admin); 
// output 
"Symfony is awesome"
User {#570 ▼
  -id: 1
  -email: "user@email.fr"
 ...

with this feature

ddd($message, $admin);
//  output 
$message : "Symfony is awesome"
$admin : User {#570 ▼
  -id: 1
  -email: "user@email.fr"
 ...
@juuuuuu

This comment has been minimized.

Copy link

commented Feb 15, 2019

That's a great idea! Will you do the PR @ismail1432?

@ismail1432

This comment has been minimized.

Copy link
Contributor Author

commented Feb 15, 2019

Yep I can give a try

@lyrixx

This comment has been minimized.

Copy link
Member

commented Feb 18, 2019

Note for thoses who don't want to wait :

dd(['message' => $message, 'admin' => $admin]);

I use this all the time

And the JS way:

console.log({message, admin});
@nicolas-grekas

This comment has been minimized.

Copy link
Member

commented Feb 18, 2019

dump(compact('myVar')) ;)

@ro0NL

This comment has been minimized.

Copy link
Contributor

commented Feb 18, 2019

from dd($var) can we even detect the "var" part? In a sane way...

@nicolas-grekas

This comment has been minimized.

Copy link
Member

commented Feb 24, 2019

from dd($var) can we even detect the "var" part? In a sane way...

I don't think so. To me, this issue is impossible to implement in any "sane" way. Yes, we can inspect the trace then use token_get_all to extract the source code and then the variable name. But this is going to be quite complex and quite fragile I fear.

Not worth it to me. I may be wrong of course.

@ismail1432

This comment has been minimized.

Copy link
Contributor Author

commented Feb 25, 2019

I tried many things without any success 😢
I will close this one in favor of @lyrixx tips 😄

@ismail1432 ismail1432 closed this Feb 25, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.