title: How can I declare that a constant is defined in PhpDoc (for intelephense)?
body: <h2>TL;DR</h2>
  <p>How can I document a constant that is defined in external code using PhpDoc/DocBlocks so that it will not show up as an undefined variable in static code analysis?</p>
  <h2>Details:</h2>
  <p>I'm trying to write a small WordPress plugin. I have some PHP code like below.</p>
  <pre><code>defined('ABSPATH') or die('Access denied!'); // Avoid direct file request
  
  function getPluginInfo($key) {
      require_once ABSPATH . '/wp-admin/includes/plugin.php';
      $data = get_plugin_data(MY_PLUGIN_FILE, true, false);
      return $data[$key];
  }
  </code></pre>
  <p>I'm using the VSCode plugin <a href="https://github.com/bmewburn/vscode-intelephense" rel="nofollow noreferrer">vscode-intelephense</a> (which provides a PHP language service). I have all the necessary dependencies installed, including listing &quot;wordpress&quot; as a stub in the VSCode settings. In general, the intelephense is working quite well and is doing a great job of showing information about my code as well as WordPress library code.</p>
  <p>However intelephense shows an error: <strong>&quot;Undefined constant '...\ABSPATH' (1011)&quot;</strong> (where the dots are a namespace that I have omitted for brevity).</p>
  <p>So it appears that intelephense doesn't pick up on the condition implied by the first line -- namely that if <code>ABSPATH</code> isn't defined, execution won't reach the later code that references it. (Which is perfectly fine, program flow analysis might be demanding too much). Anyway, I think I should be able to add some kind of PhpDoc (or another commented annotation) to indicate to code analyzers that the variable <strong>is</strong> defined. Something like this:</p>
  <pre><code>/**
   * @var string ABSPATH
   */
  </code></pre>
  <p>or this:</p>
  <pre><code>/**
   * @global string ABSPATH
   */
  </code></pre>
  <p>But neither of those cause the error to go away. (I also tried <code>@const</code> which doesn't appear to be a real tag. It didn't work either.)</p>
  <p>Is there some way in the code I can indicate that ABSPATH is defined in external code or in an out scope? Adding a line at the top of the function like <code>global ABSPATH;</code> doesn't seem to be right either, because <code>ABSPATH</code> isn't a variable. It's a <code>define</code>-created constant.</p>
  <p>Thanks!</p>