Skip to content

Add support for PhpParser v5 for PHP 7.4+ #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 18, 2025

Conversation

IanDelMar
Copy link
Contributor

This PR adds support for nikic/php-parser v5 for PHP 7.4+, while retaining compatibility with v4 for PHP 7.3.

Key Changes

  • The parts property of PhpParser\Node\Name was deprecated in v4 and removed in v5. It has been replaced with a call to getFirst(), which is available in both major versions.
  • The create() method and the PREFER_PHP7 constant were removed from PhpParser\ParserFactory in v5. This PR uses the createForNewestSupportedVersion() method instead, which is available in both v4 and v5. According to the upgrade guide, this method is "roughly equivalent to PREFER_PHP7 behavior".

Testing

The changes were tested with php-stubs/wordpress. Output under v5 (5.4.0) differs slightly but improves correctness:

  • No longer adds incorrect slashes.
  • Preserves the correct order of final and visibility modifiers.

Closes #25
Closes #31

@szepeviktor
Copy link
Member

Thank you.

@szepeviktor szepeviktor merged commit 820db58 into php-stubs:master Apr 18, 2025
8 checks passed
@IanDelMar IanDelMar deleted the parser-v5 branch April 18, 2025 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support symfony/filesystem ^7.0 Outdated locked dependencies need updating
3 participants