Why XDebug doesn't see that variable at the breakpoint?

Why XDebug doesn't see that variable at the breakpoint? View the contents of the array is possible only in case, if you continue the program execution a step further.
Jumped on the trail. string
June 5th 19 at 21:16
1 answer
June 5th 19 at 21:18
The fact that the stop point is a point which WILL be made, and not ALREADY done. Ie when XDebug stops on the line
$arr = [0,1,2,3,4,5];
this means that this line only WILL be performed. Accordingly, as to this line, the variable $arr is nowhere declared, then before executing this line the variable does not exist. Variable is created during execution of this line.

If the question is, why the variable does not exist before the execution of line
$arr = [0,1,2,3,4,5];
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;
 return null;

$arr = TestFunction();


In this case, the variable $arr can get radically different values depending on the fact that it's in the query. PHP is unable to predict what type of variable to create $arr before you run the function TestFunction(). That is why, in PHP variables do not exist until the first assignment. It is a feature of any language with dynamic typification.

Find more questions by tags PhpStormXdebug