G
G
gimade2018-05-18 11:42:17
xdebug
gimade, 2018-05-18 11:42:17

Why doesn't XDebug see what's in the variable at the breakpoint?

Why can't XDebug see what's in the variable on the breakpoint? You can view the contents of the array only if you continue the execution of the program one step ahead.
Breakpoint:
5afe923c86a64681444370.png
Jumped onto the trail. string
5afe9269bb56b118235428.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Merzley, 2018-05-18
@gimade

The point is that a breakpoint is a point that WILL be executed, not ALREADY executed. Those. when XDebug stops at a line it means that the line WILL only be executed. Accordingly, since the variable $arr is not declared anywhere before this line, the variable does not exist at all before this line is executed. The variable is created during the execution of this line. UPD If the question is why the variable does not exist before the line is executed, then imagine a hypothetical situation

function TestFunction(){
    if ($_REQUEST['some_key'] == 1)
        return [1,2,3,4,5];
    else if ($_REQUEST['some_key'] == 2)
        return '12345';
    else if ($_REQUEST['some_key'] == 3)
        return 12345;
    //и т.д.
    else
        return null;
}

$arr = TestFunction();

var_dump($arr);

In this case, radically different values ​​can get into the $arr variable, depending solely on what came in the request. PHP is unable to predict what type of variable to create for $arr before TestFunction() is executed. This is why in PHP variables don't exist until the first assignment. This is a feature of any language with dynamic typing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question