Skip to content

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

@lazka

Description

@lazka

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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions