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

Does not skip code guarded by PHP_VERSION_ID resulting in "Internal error: syntax error" #6386

Closed
lazka opened this issue Jan 17, 2022 · 6 comments

Comments

@lazka
Copy link

lazka commented Jan 17, 2022

Bug report

I'm using api-platform and they have recently started to include php8 only files and guard their uses via PHP_VERSION_ID checks. For example:

https://github.com/api-platform/core/blob/4ec515837cf696788e828a61005594fffc4cf244/src/Util/ClientTrait.php#L16

which then conditionally includes:

https://github.com/api-platform/core/blob/4ec515837cf696788e828a61005594fffc4cf244/src/Util/ClientTrait80.php#L18

which is PHP8 only syntax, and fails with PHP 7.4.

Related downstream issue: api-platform/core#4614

Code snippet that reproduces the problem

<?php
// composer require api-platform/core phpstan/phpstan symfony/framework-bundle phpunit/phpunit symfony/http-client

declare(strict_types=1);

require_once __DIR__.'/vendor/autoload.php';

use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Client;

class Test extends ApiTestCase
{
    protected function setUp(): void
    {
        parent::setUp();
        static::createClient();
    }
}
$ php7.4 ./vendor/bin/phpstan analyze a.php
 ------ ---------------------------------------------------------------------- 
  Line   /a.php                                                                
 ------ ---------------------------------------------------------------------- 
         Internal error: syntax error, unexpected 'static' (T_STATIC)          
         Run PHPStan with --debug option and post the stack trace to:          
         https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md  
 ------ ---------------------------------------------------------------------- 

Expected output

No output

Did PHPStan help you today? Did it make you happy in any way?

every day :)

@mergeable
Copy link

mergeable bot commented Jan 17, 2022

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, can you please create a small reproducing repository that shows this problem? Thanks.

@lazka
Copy link
Author

lazka commented Jan 17, 2022

-> https://github.com/lazka/phpstan-api-platform-php8-syntax-issue

I hope this is small enough.

@ondrejmirtes
Copy link
Member

Thank you, perfect. I'm gonna look into it in the next few days.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@433511a

Regression test: a1217f8

@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 Feb 19, 2022
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