ARTICLE AD BOX
I'm using the extension PHP intelephense for Visual Studio Code.
$root = $_SERVER['DOCUMENT_ROOT']; include($root . '/sqlcon.php'); $gettextquery = mysqli_query($con, "SELECT * FROM `pics` WHERE ai_cats = ''");I get
Undefined variable '$con'
even though $con is defined in sqlcon.php.
Everything worked until recently. I've tried to solve it by clearing cache and restarting.
1
Intelephense does static analysis — it doesn't actually execute the include, so it can't follow $_SERVER['DOCUMENT_ROOT'] at runtime to find $con.
One quick fix would be to add a stub at the top of your file:
/** @var mysqli $con */Or check your intelephense.environment.includePaths setting in VS Code and add your root path there so it can resolve the include statically.
I'm just switching from
$root = $_SERVER['DOCUMENT_ROOT'];
to
_DIR_
now, intelephense recognizes the variables and their types in included files without any problem again with that
Explore related questions
See similar questions with these tags.


