On this page:
- Evaluating arbitrary expressions
- Evaluating expressions in the editor
- Evaluating variables in the console pane
- Executing code in the console pane during a debugging session
- A method can be invoked within the Expression Evaluation 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.
Evaluating arbitrary expressions
- Open the Evaluate Expression dialog box in one of the following ways:
- In the
dialog box, specify the expression you want to evaluate. Do one of the following:
- In the Expression field, type the expression in question or choose one of the previously evaluated expressions from the drop-down list.
- To evaluate a code fragment, click the Code Fragment Mode button and fill in the Code Fragment text box.
- Click the Evaluate button. The Result read-only field shows the evaluation output. If the specified expression cannot be evaluated, the Result field explains the reason.
Evaluating expressions in the editor
During a debugger session, the value of any expression is shown in the tooltip every time you hover your mouse pointer over it. If an expression contains children, clicking expands the node and displays all children.
There are two ways to evaluate an expression quickly:
By using the Show value tooltip on code selection functionality:
- In the Debugger | Data Views settings page, enable the Show value tooltip on code selection option.
Select a code fragment with the mouse, or by clicking
Ctrl+W. A tooltip with the expression value automatically appears under the selection and changes each time you change the selection:
- By manually invoking the tooltip with the expression value:
Evaluating variables in the console pane
- Select the variable in question in the Variables pane and choose
Evaluate in Console on the context menu of the selection.
When you switch to the Console pane, the variable name is shown in green at
>and its value is displayed below in blue.
Alternatively you can type the name of any variable at
>in the Console manually 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 without searching for it in the Variables pane, find the variable in question 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, etc. 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 check box on the Debug page.