Eclipse Php : variable undefined evenif it is defined in an require_once php file

xdebug.idekey phpstorm
php require_once
xdebug documentation
php require vs require_once
xdebug.remote_host docker
phpstorm xdebug remote
xdebug.idekey vscode
xdebug profiler

I am using as a beginner : Eclipse IDE for PHP Developers Version: Photon Release (4.8.0) Build id: 20180619-1200 OS: Windows 10, v.10.0, x86_64 / win32 Java version: 1.8.0_77

I have a file index.php with a require_once(initialisation.php) The initialisation.php defines a variable $Modeles_Chemin And the variable $Modeles_Chemin is used in index.php (after the require_once)

On my website, it works fine no undefined variable but in eclipse editor I receive an undefined variable.

(Of course I have the same problem with the other variables).

Here is an extract : index.php :

<?php
require_once("prog/php/initialisation_site.php");
include($Modeles_Chemin.$Modeles_Nom."/html_begin.php");

initialisation_site.php :

        $Contenu_Chemin = "contenu/";
$Modeles_Chemin = $Contenu_Chemin."modeles/";

How can I fix this ?

thanks

You can use global:

require_once("prog/php/initialisation_site.php");

global $Modeles_Chemin;
global $Modeles_Nom;

include($Modeles_Chemin.$Modeles_Nom."/html_begin.php");

Eclipse Php : variable undefined evenif it is defined in an , I have a file index.php with a require_once (initialisation.php) The initialisation.​php defines a variable $Modeles_Chemin And the variable  Re: Eclipse Php : variable undefined evenif it is defined in an require_once php file [message #1791943 is a reply to message #1791929] Sun, 08 July 2018 16:58 Stéphane Bertho

This probably means that Eclipse does not understand that those variables are defined in the file that you import with require_once.

Maybe it is possible to switch the annotation for undefined variables off in the Eclipse settings? But then you'd also not see warnings for other undefined variables.

Documentation » All settings, I have a file index.php with a require_once(initialisation.php) The initialisation.​php defines a variable $Modeles_Chemin And the variable  Eclipse Php : variable undefined evenif it is defined in an require_once php file

If you want to get rid of these warnings you may consider putting this kind of comment on the top of the file:

/** @var Type $variable */

This is a workaround but I find it to be a good approach. This kind of a comment is letting me know that I am using a variable that is defined in a different file.

require - Manual, This setting, defaulting to 0, controls whether Xdebug should add variable the filename used in include(), include_once(), require() or require_once() to the trace files. 1 in the CLI version of PHP it will not have the tool tip, nor in output files. If you want to dump undefined values from the superglobals you should set this  Eclipse Php : variable undefined evenif it is defined in an require_once php file. By: Stéphane Bertho on Mon, 02 July 2018. 5: 3911: Mon, 26 November 2018 22:16

[PDF] Learning PHP, MySQL, JavaScript, and CSS, In other words, it will halt the script whereas include only emits a warning function, just as when defined from inside any other function, are always global\n"​; echo $b; // "While the variable b is a local variable of the function\n" As the manual states require and require_once as of PHP 4.02 no longer call the file if the  4 Eclipse Php : variable undefined evenif it is defined in an require_once php file Sep 5 '18 4 How to manage GET Method in an API Jan 21 '16 3 Charging an account in Stripe Aug 18 '15

Magic Methods, PHP Functions. 94. Defining a Function. 95. Returning a Value. 96. Returning an Array. 97. Passing by Reference. 98. Returning Global Variables. 99. Recap of  Be careful when using symbolic links, because require will search the real path of the file and not the path relative to the symbolic link. Imagine your script A.php resides on directory /a and you create a symbolic link for it on directory /b/c.

Undefined variables in included files in php – IDEs Support (IntelliJ , PHPEclipse. This PHP file can include Notice: Undefined variable: myUndefined in C:\xampp\htdocs\mypage.php on line 10 of a class may be created even if the class definition appears further down in the script file. Require_ once. The require_once statement works like require , but it does not import a file if it has. It seems that static variables defined within a class method or static function are stored separately for the class and each extended class of it. It's sort of like, every time you extend a class, functions with static variables are re-writen, and the static variable re-created. Even if the function is defined as final! <?php class A {

Comments
  • In the same file "initialisation_site.php" I have string variables and class objects. Eclipse can "see" the class but not the string variables. Why ????
  • Related: bugs.eclipse.org/bugs/show_bug.cgi?id=538418
  • $Modeles_Nom: Where is this variable defined?
  • It looks like $Modeles_Nom is he undefined a. Pretty obvious actually!
  • @delboy1978uk I know that he made a mistake to place that undefined variable there but the problem is about Eclipse PHP Variable Validator ignores include and require.
  • This looks more like a comment than any solution.
  • That means that all my PHP includes or requires will not be seen as part of the php file where they included ? I am sure Eclipse can do better