Psalm: Upgrade to PHP-Parser 4.0

Created on 18 Mar 2018  Â·  13Comments  Â·  Source: vimeo/psalm

This is pretty significant improvement https://github.com/nikic/PHP-Parser/releases/tag/v4.0.0

I have created this issue, because I think it would be good to do for your project to do ASAP. Reason for that is observation in PHPStan community. PHPStan is unwilling to do this step, because there already exist lot of community extensions for it which expect version 3 of a parser and this bump would break them, as they don't list ast parser version in their dependencies explicitly.

Therefore I suggest to do this bump while still having very small community plugin base.

enhancement

Most helpful comment

If you wanted to bump the version to e.g. 1.1 for PHP-Parser 4.0 support I can promise that won't break anything I'm using Psalm for.

All 13 comments

It's not just about extensions – a lot of projects depend on PhpParser 3 for other reasons (e.g. code formatting tools).

I have a pretty up-to-date branch with PHP Parser v4 support but won't merge until the next major version, as it requires PHP 7.0, and Psalm currently supports PHP 5.6. It also doesn't bring any sizeable benefits to Psalm itself (but I can see the benefits for other packages).

Code formatting tools don't use ast extension, because nikic extension didn't allow to modify source code until version 4. Specifically both phpcs and php-cs-fixer use php tokens. Only tool modifying source code using ast extensions I am aware of is rector and it does that thanks to parser 4.

Contrary, staying on parser version 3 would present a challenge to ecosystem, because those tools will feel same hesitance you have right now - they will say that other static analysis tools use parser version 3, hence won't start using it.

Not sure how important is holding on to PHP 5.6 though. Another thing I like about Psalm in constrast to PHPStan is that it doesn't require sharing runtime environment with application. So it can run from a docker or VM or totally diffent machine.

Not sure how important is holding on to PHP 5.6 though

A number of packages use Psalm chiefly because it still has PHP 5 support (e.g. those from @paragonie-scott). I will support PHP 5.6 officially until the end of 2018 when it gets EOLed. That doesn't preclude a PHP7-requiring release before then, but if that happens it'll be because PhpParser v3 support becomes a sticking point to a number of people.

If you want to use PHP Parser v4 feel free to check out that branch and give it a go – I'd love to know if anything breaks.

Just for the record: tried the branch, no issues.

If you wanted to bump the version to e.g. 1.1 for PHP-Parser 4.0 support I can promise that won't break anything I'm using Psalm for.

PHPStan is unwilling to do this step, because there already exist lot of community extensions for it which expect version 3 of a parser and this bump would break them

This is not true. I'm unwilling to do that in a minor version but it's on the roadmap for PHPStan 0.10 in Q2 2018. Of course I want to update dependencies eagerly and not get stuck on an old version.

  • unwilling to do in minor version

Come on, read between lines. Of course I don't mean you won't do the upgrade ever.

I'm just careful about possible FUD spreading 😊

Just realized parser 4.0 can be really handy for psalter as well. Just wanted to try write a plugin, got hesitant when I realized it would need to be done with tokens.

You should work against the dev-phpparser-4 branch, which is regularly rebased off master (I did it earlier today, as I'm working on LSP support which requires it).

PHP Parser 4 is useful enough that I'll likely merge that branch into master in April and create a new 2.0 release.

Oh, great news. I'll probably use that branch then!

@ostrolucky feel free to use dev-master - I'll create a prerelease for v2 this week.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vudaltsov picture vudaltsov  Â·  3Comments

orklah picture orklah  Â·  3Comments

ADmad picture ADmad  Â·  3Comments

weirdan picture weirdan  Â·  4Comments

Pierstoval picture Pierstoval  Â·  3Comments