psalm: ParseError in (ignored) vendor symfony/polyfill-mbstring/bootstrap80.php

In two symfony 4.4 projects we use PHP 7.2. After updating to the newest release 1.22.0 of symfony/polyfill-mbstring wo got the following new error after running psalm

ERROR: ParseError - vendor/symfony/polyfill-mbstring/bootstrap80.php:125:86 - Syntax error, unexpected '=' on line 125 (see https://psalm.dev/173)
    function mb_scrub(string $string, string $encoding = null): string { $encoding ??= mb_internal_encoding(); return mb_convert_encoding($string, $encoding, $encoding); }

The vendor folder itself is ignored.

While I understand this cannot be parsed by PHP 7.2, I do not understand why the PHP 8 bootstrap file is analysed at all. The only reference is in symfony packages with a PHP version check.

if (\PHP_VERSION_ID >= 80000) {
    return require __DIR__.'/bootstrap80.php';
}

Do I miss something or is this a problem in psalm?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 15
  • Comments: 27 (3 by maintainers)

Commits related to this issue

Most upvoted comments

<ignoreFiles><directory name="vendor" /></ignoreFiles> doesn’t work in this case. I tried add ignore directly <ignoreFiles><file name="vendor/symfony/polyfill-mbstring/bootstrap80.php"</ignoreFiles>, but it doesn’t work too. Someone tried fix this issue in symfony/polyfill-mbstring, but looks like problem is vimeo/psalm site. https://github.com/symfony/polyfill/pull/327

@klebann you can also require dev-master to get the fix.

I’m going to propose a PR that would avoid scanning files that are conditionally included based on PHP_VERSION_ID (as is the case with multiple symfony polyfills).

For anyone not wanting to use the master branch of psalm, you can explicitly specify a version of symfony/polyfill-mbstring without the offending file:

composer require symfony/polyfill-mbstring:v1.20.0

you can use composer require --dev vimeo/psalm:master to use directly the last commit made here. Beware of stability though, it may break at any moment and does not necessarily reflect what will be in the next release. I’d advise going back to a named release as soon as the fix is released if you can.