Skip to content
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

Named arguments false positive with attributes and PHP 7.4 #5898

Closed
iquito opened this issue Nov 2, 2021 · 4 comments
Closed

Named arguments false positive with attributes and PHP 7.4 #5898

iquito opened this issue Nov 2, 2021 · 4 comments

Comments

@iquito
Copy link

iquito commented Nov 2, 2021

Bug report

A project of mine runs on PHP 7.4 but already has some "forward-compatible" attribute syntax for the switch to PHP8 included (it is tested for both versions, but the server has not been upgraded yet), which with PHPStan 1.0 leads to errors that cannot be ignored or baselined.

Code snippet that reproduces the problem

Symfony project with controllers like the following, with annotations for PHP 7.4 and attributes for when the project switches to PHP8:

class PhoneNumberChangeController
{
    /**
     * @Route("/phone_number/change", methods={"POST"}, name="phone_number_change")
     */
    #[Route('/phone_number/change', methods: ['POST'], name: 'phone_number_change')]
    public function __invoke(Request $request): Response
    {
    }
}

Leads to the following errors, when I run it with PHP8 CLI (not sure if it would also appear with PHP 7.4 CLI):

Named arguments are supported only on PHP 8.0 and later. for the Route attribute definition, yet for PHP 7.4 that attribute definition is just a comment.

Expected output

An advantage of the attribute syntax in PHP is that you can start adding it while still using PHP 7.4 - in that case I would expect PHPStan to ignore all attributes if the project is set to run on PHP 7.4. This is also an error that cannot be ignored - it cannot be added to the baseline file, PHPStan reports this when I try: Some errors could not be put into baseline. Re-run PHPStan and fix them..

As a positive last note: PHPStan 1.0 has become really fast, and this is the only problem I noticed in all my projects when upgrading, thanks for all your work!

@mergeable
Copy link

mergeable bot commented Nov 2, 2021

This bug report is missing a link to reproduction on phpstan.org.

It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

Hi, this is a funny error, yeah, it doesn't make sense to report this for attributes 😂

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@6366066

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants