Skip to content

Conversation

@LinusU
Copy link
Contributor

@LinusU LinusU commented Jan 18, 2025

I'm using an absolute ancient version of PHP at work (got handed a 10+ year old project I now need to maintain 🙈) and are constantly running into problems with me using features that aren't implemented. So this linter is actually great for me!

This PR adds the ability to configure the php_version all the way down to "5.4".

There is still some rules missing in order to cover 100% of the features introduced between 5.4 and 7.3, but I think that this is a good start! 🐎

Please let me know if I'm doing anything wrong, which I probably am 😅

Here is a screenshot of it in action:

Screenshot 2025-01-18 at 16 50 34

Copy link
Member

@azjezz azjezz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this approach, but I believe we should define the minimum PHP versions we officially support:

  • >= 7.4: This version is well-tested and reliable with Mago.
  • >= 5.4: This can be allowed, but with caution.

The reasoning is that PHP 7 and PHP 8 introduced significant changes, particularly around operator precedence and associativity (left, right, or none). While Mago ( esp. the parser ) might work with your codebase, it could potentially fail or behave unexpectedly with others.

impl Rule for FinallyFeatureRule {
fn get_definition(&self) -> RuleDefinition {
RuleDefinition::enabled("Finally Feature", Level::Error)
.with_maximum_supported_php_version(PHPVersion::PHP54)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.with_maximum_supported_php_version(PHPVersion::PHP54)
.with_maximum_supported_php_version(PHPVersion::PHP55)

this has became exlusive now.

.with_annotation(
Annotation::primary(param.span()).with_message("Variadic parameter used here."),
)
.with_note("Use `func_get_args()` if you need compatibility with older PHP versions.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.with_note("Use `func_get_args()` if you need compatibility with older PHP versions.");
.with_help("Use `func_get_args()` if you need compatibility with older PHP versions.");

notes are used to provide more information, help are used to provide a solution, or a workaround.

@azjezz
Copy link
Member

azjezz commented Jan 18, 2025

We could improve support for PHP 5.x to the point where no warnings would be necessary, but achieving this would require:

  • Compiling a comprehensive list of syntax changes between PHP 5.x and PHP 8.
  • Updating the lexer and parser to adapt based on the specified PHP version.

When I mention making the parser version-aware, I'm primarily referring to handling elements like operator precedence. The parser would still process features from future PHP versions, provided they don't conflict with syntax from earlier versions. For example, features like property hooks can be parsed safely even if the version is set to PHP 5.4.

@azjezz azjezz added Priority: Medium This issue may be useful and needs attention. Status: Revision Needed Multiple reviewers found issues in the PR that need addressing. Type: Enhancement Request for additions or changes that improve existing functionality. Subject: Linter An issue or PR related to the linter. Subject: Parser An issue or PR related to the parser, lexer, or ast. labels Jan 23, 2025
@azjezz azjezz force-pushed the main branch 4 times, most recently from a8dd89b to 8c94f8c Compare February 21, 2025 01:50
@azjezz
Copy link
Member

azjezz commented Sep 1, 2025

@LinusU I'll be closing this PR.

Mago has changed quite a lot since this PR was opened, it can't be merged anymore. and after fighting with a lot of precedence issues in the parser recently, I think adding PHP 5.x support would make the parser much more complicated.

@azjezz azjezz added the Status: Closed This issue is closed and no more work is planned. label Sep 1, 2025
@azjezz azjezz closed this Sep 1, 2025
@LinusU
Copy link
Contributor Author

LinusU commented Sep 2, 2025

@azjezz sounds good!

Sorry for never getting back to this, at the moment I'm not doing any more PHP at work, but happy to hear that your tool has evolved! 🤩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: Medium This issue may be useful and needs attention. Status: Closed This issue is closed and no more work is planned. Status: Revision Needed Multiple reviewers found issues in the PR that need addressing. Subject: Linter An issue or PR related to the linter. Subject: Parser An issue or PR related to the parser, lexer, or ast. Type: Enhancement Request for additions or changes that improve existing functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants