Variables not recognized by PHPStorm
I created a function that includes the below code. I am able to work with the $names_str and $values_str
variables which are all local. However when I expanded the code and added the $btest vars, none of them
show up in the scope of variables for the code, nor are they able to be evaluated. At first I thought
it was only arrays, but now it is the same for any var type. Does anyone have info on why PHPStorm
would treat vars different after the initial code is written? I have tried Save All, Deployment, etc. and
the compare always reports that the server version is identical. I can move through the code and
set break points without issue. The only issue is that it is not initializing or updating the variables.
Any information is greatly appreciated.
Please note that PHPStorm is running the latest (July 22, 2020) version and
that the cache has been invalidated and recreated and the program restarted.
From what I can see, it seems to be a problem when the file is included. I can create
and see the vars in a php file. But when the vars are in functions that are in inlcuded php files (using require)
the issue arises. The IDE does recognize that the vars are used (they color does change from grey) but
the inline evaluations do not appear. This has brought development to a halt.
The odd thing is that the originally created vars work fine, yet new ones are not recognized.
And any new functions added to the file are not recognized. Its as if PHPStorm's IDE
flipped a switch since this yesterday and not longer can I modify this PHP file of functions for
inclusion in the overall program. This is not a scope issue. When the frame appears those
new vars simply cannot be modified via program control nor does the IDE show any info when they
are hovered over. But the right side of the equation does show info when hovered over.
The var names are valid and there are not errors returned when each statement is executed via F8.
$names_str = substr($names_str, 0,-1);
$values_str = substr($values_str, 0, -1);
$btest1 = 1;
$btest2 = "Test";
$btest3 = array("btest1" => "1", "btest2" => "1", "btest3" => "3");
$btest4 = array(1,2,3);
请先登录再写评论。
Hi there,
Please provide screenshots (whole IDE window).
Please also try your code in a brand new project by having as little code/files as possible (to create a reproducible code sample).
In general: debugging-related issue (not showing in vars and similar) must be related to your debugger extension (Xdebug) and how it works with OPCache -- it may remove "dead" / not used variables for optimisation purposes and Xdebug will simply not be able to see them.
P.S.: the issue might be present in a web page debug but absent in a CLI (the way how it works/configured -- by default OPCache is completely disabled for CLI)
Attached are the screen shots. I am not using CLI. XDebug has been working fine but I have added code that uses the variable to take that possible issue out. The issue is present only in functions. As you can see from the attached, when I run the code from a function in the same php file, it does not show any evaluation to the right inline nor does it add the var at the bottom in the var window. But when I copy the contents of the function to the main block, it works fine as shown by the evaluation of the var as well as adding it to the list of vars at the bottom of the IDE. I have been using PHPStorm since at 2016 without this problem and now something changed that is preventing simple creation of variables beyond the main body of text.


What are your IDE, PHP and Xdebug versions?
This works just fine for me in these test files (see screenshot) using PhpStorm 2020.1.4 on Windows 10 x64, IIS web server, PHP 7.4.7 x64 nts, Xdebug 2.9.6
I've tried CLI debug (initiated from IDE), Web debug (initiated from IDE as well as via Xdebug browser extension) -- got the same result in all 3 cases.
Please share your phpinfo() output: in particular Xdebug and OPCache sections. Could also be a Xdebug setting.
Technically that variable is not used anywhere in a function (those assignments are useless as they do not affect anything) and PHP (OPCache) may remove them for optimisation purposes.
You should enable and collect Xdebug log: it will show if that variable is reported by Xdebug or not (PhpStorm cannot show info if debugger extension does not report that info in the first place). Please collect and share such log (actual file, not just a text) where var is not shown (do not mix them together; make it a clear to read) to see what Xdebug reports.
I have seen similar issues before (once or twice here on Forum/Issue Tracker, few times on Stack Overflow). Could not locate them all especially here where the search is quite "wild", just these ones for now:
As a recap, it was OPcache's doings, we've figured that out in a support ticket.