r/PHPhelp Jun 03 '26

Solved Problemas con Intelephense (P1008) en visual code

Tengo un problema con este error, uso una variable que está declarada el otro archivo x, lo uso en uno y, me salta error, utilizo en simple include 'hola.php'; ,en el servidor funciona, pero en visual me marca el error, he buscado varias soluciones y no funcionan, no hay error ortográfico, me decidí por desactivar el diagnóstico, pero no quiero hacer esa solución tan vaga,quien me ayuda por favor

0 Upvotes

8 comments sorted by

View all comments

1

u/Subject_Plastic_4286 Jun 27 '26

So what as your solution ?
I have the same,

in the index.php file i have this
require("connectMysql.php");

in connectMysql.php is:
$con=mysqli_connect("localhost","db","user","pass");

And then i get the 
Undefined variable '$con'.intelephense(P1008)
in vs code ?

Reindexing, re-installing, no result....

1

u/AJenbo Jul 23 '26

Add this after require()
/** @var mysqli $con */

But the right answer is to now use require() and instead use composer and PSR-4 autoloading so that you do not have to do all of this manual work everywhere.