With PhpStorm, you can not only view values of separate variables, but also evaluate more complex expressions, such as method calls, operator expressions, lambda expressions, and anonymous classes.
Evaluating expressions in the editor
The easiest way to evaluate expressions is to use editor tooltips. If the value of a variable or an expression contains child elements, clicking expands the node and displays all children.
When Show value tooltip is enabled on the page of PhpStorm settings (Ctrl+Alt+S), you can hover the mouse over variables and expressions to see the evaluated results:
When Show value tooltip on code selection is enabled on the page of PhpStorm settings (Ctrl+Alt+S) PhpStorm shows the evaluation result for the selected expression. You can extend or shrink the selection with Ctrl+W/ Ctrl+Shift+W thus changing the evaluated expression:
You can also invoke the value tooltip on a variable, expression, or selection with the Quick Evaluate Expression command (Ctrl+Alt+F8 or Run | Quick Evaluate Expression ).
Evaluating arbitrary expressions in the dedicated dialog
The Evaluate dialog lets you play with variables and expressions in the current context — you can perform various operations and call methods on them, and then analyze results that you get with their current values
The Evaluate dialog is non-modal, so you can switch the focus back to the editor to copy other variables and expressions, and you can also open multiple Evaluate dialogs if necessary.
While evaluating expressions, mind the following
A method can be invoked in the Evaluate dialog only if the debugger has stopped at a breakpoint, but has not been paused.
Expression evaluation can only be "single-level". In other words, if PhpStorm stops at a breakpoint within a method called from the Expression Evaluation, you cannot use the Expression Evaluation feature again.
To evaluate an arbitrary expression
If you want to start with some expression or a variable, select it in the editor or in any view in the Debug window.
Open the Evaluate dialog in one of the following ways:
Selectfrom the context menu.
Choosefrom the main menu.
Click on the toolbar of the Debug window.
If you have selected something at the first step, the variable or expression will be displayed in the Expression field. Otherwise, type the expression in the field or choose one of the previously evaluated expressions from the list.
Press Enter or click Evaluate. The read-only Result field will show the evaluation output.
If you have assigned a label to an object, you can reference it by this labelIf the specified expression cannot be evaluated, the Result field explains the reason.
<label-name>_DebugLabel. PhpStorm also displays this label in the completion suggestion list.
If you want to edit a multi-line expression or a code fragment, click in the Expression field or press Shift+Enter to switch to the multi-line Code fragment view and back.
To switch between the evaluated fragments, press Alt+Down and Alt+Up.
Optionally, you can select another thread where you want an expression to be evaluated in the Frames pane of the Debug window.
Evaluating variables in the console pane
Select a variable in the Variables pane and select from the context menu.When you switch to the Console pane, the variable name is shown in green at
>and its value is displayed below in blue.
Alternatively, type the name of any variable at
>in the Console and press Enter to have its value displayed.
Code completion is at your disposal: as you type the name of a variable, PhpStorm displays a suggestion list.
Note that this functionality is available only when the Use Console Input toggle button is pressed.
To evaluate a previously evaluated variable, find it using the Up and Down arrows on you keyboard and press Enter.
Executing code in the console pane during a debugging session
During a PHP debugging session, you can not only evaluate variables, but also change their values, call PHP functions, and define additional ones right in the Console pane. Note that this functionality is not available for PHPUnit or Behat run/debug configurations.
Start a debugging session (see PHP Debugging Session) and switch to the Console pane of the Debugger tab.
Press the Use Console Input toggle button on the toolbar.
Type a statement or expression at
>and press Enter. PhpStorm evaluates your code fragment and shows the output below the input code. You can type most PHP constructs including class declarations, function declarations, variables, expressions, and so on. Code completion is at your disposal: as you type, PhpStorm displays a suggestion list.
When typing a multi-line code fragment, press Shift+Enter to start a new line and Ctrl+Enter to split a line.
Output for arrays and objects is by default wrapped in a
var_export()function and displayed in the Console. To hide the output displayed, clear the Show array and object children in Debug Console checkbox on the Debug page.