pdt icon indicating copy to clipboard operation
pdt copied to clipboard

Declared variable used in a subsequently included file is marked as unused

Open basilgohar opened this issue 4 years ago • 4 comments

Describe the bug A variable defined in a page and then only used in a subsequently included file, such as a template, is marked as "never used".

Describe the eclipse environment Eclipse Platform Version: 4.15.0.v20200305-0155 PDT 7.1.0.202002212050

Describe your system

  • OS: Linux
  • Fedora 32
  • PHP 7.4.6
  • Webserver Version (if related) N/A
  • Utilis (composer, php unit, Xdebug etc...)

To Reproduce Steps to reproduce the behavior:

//  Main.php
$pageTitle = 'Create User Records in All Databases';

//  Include Header

include __DIR__ . '/inc/header_start.html.inc';
//  header_start.html.inc
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" />
<title><?=$pageTitle?></title>

Expected behavior $pageTitle in recognized as being used in /inc/header_start.html.inc

Screenshots If applicable, add screenshots to help explain your problem.

Selection_076

Selection_077

Additional context The template file has the corresponding, Variable '$pageTitle' is undefined error, so hopefully the fix would be reciprocal in this case.

basilgohar avatar Jun 14 '20 11:06 basilgohar

Current implementation support only same-file. In general file-includes are never takes into account, so I'm marking as enhancement.

zulus avatar Jun 14 '20 14:06 zulus

Current implementation support only same-file. In general file-includes are never takes into account, so I'm marking as enhancement.

This is fine. I cannot remove the bug label myself, though.

basilgohar avatar Jun 14 '20 15:06 basilgohar

When a file uses a variable that's defined elsewhere, I usually start it with

<?php
/**
  * @var MyType1 $myVar1
  * @var MyType2 $myVar2
  */

mlocati avatar Jun 14 '20 16:06 mlocati

When a file uses a variable that's defined elsewhere, I usually start it with

<?php
/**
  * @var MyType1 $myVar1
  * @var MyType2 $myVar2
  */

Yes, that will also work. So I can do that, I just prefer to not have to do that. :-p

basilgohar avatar Jun 14 '20 16:06 basilgohar