Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to copy a data structure from the 'Variables' window in the debugger?

Tags:

phpstorm

When debugging in PhpStorm, I am aware that you can right click on a variable in the 'Variables' pane, and select the context menu item 'Copy Value'. Is there a way to copy a data structure, such as an array or object?

$_GET = {array} [1]
    someVariable = "Hello this is a value, and it happens to be a string"
    anotherVar   = "What is this string"

If i right-click on 'someVariable' and select 'Copy Value', I will have the string on my clipboard.

If I right click on the line with the array and select 'Copy Value', I get '[1]' on my clipboard.

What I would really like is when I right click and 'Copy Value' on the array to have something like this on my clipboard:

'[ 'someVariable' = 'Hello this is a value, and it happens to be a string', 'anotherVar' = 'What is this string ]'

Any ideas, or does someone need to make this plugin? ;)

like image 796
user1798627 Avatar asked Apr 30 '14 17:04

user1798627


1 Answers

Starting with PhpStorm version 9.0.0 (released July 8, 2015):

  • When debugging in PhpStorm, right click on a variable in the 'Variables' pane, and select the context menu item 'Copy Value As...' to copy the variable as result of one of print_r, var_export or json_encode.

With PhpStorm <9.0.0, I was using the following trick (PhpStorm 8.0.2):

  • When debugging in PhpStorm, right click on a variable in the 'Variables' pane, and select the context menu item 'Evaluate Expression...'.
  • The Evaluate Expression is opened with your variable in the "Expression:" field. In your case $_GET
  • In the "Expression:" wrap your variable with the var_export function. In your case: var_export($_GET,1). (The second parameter is set to 1 to return the variable representation instead of outputting it)
  • Click the "Evaluate" button to see the result on the "Result:" text area.
  • Right click on your result and select "Copy Value" or use copy shortcut
  • Enjoy! (If you prefer a different output you can use other functions as well, for example print_r($_GET,1))
like image 174
cgaldiolo Avatar answered May 25 '23 06:05

cgaldiolo