0

I have a config file that's included in a function, like this:

function getConnection() {
  include 'config.php';
  return new Connection($config['host']);
}

The issue is to make Psalm recognize the $config variable from the config file. Possible? Preferable using array shape notation.

Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57

1 Answers1

1

Solved by adding a /** @var ... annotation above the include line:

function getConnection() {
  /** @var array{host: string} $config */
  include 'config.php';
  return new Connection($config['host']);
}

Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57