Skip to content

Could not read file from PHP extension #2838

@meridius

Description

@meridius

Bug report

This bug relates to ancient #598 which is about PhpStan not being able to load classes from PHP extensions. It has reappeared since PhpStan 0.12.0 presumably because of switch to Roave/BetterReflection which loads classes from PHP extensions differently.

The extension in question is (like with the aforementioned bug) Couchbase 2.2.0.

Code snippet that reproduces the problem

<?php declare(strict_types = 1);

class CouchbaseApplePassRepository
{
    private $bucket;

    public function __construct(
        \CouchbaseBucket $bucket
    ) {
        $this->bucket = $bucket;
    }
}

Expected output

There should not be any error.

Output of tested versions

0.12.4

$ phpstan analyse --level=7 --configuration=phpstan.neon --ansi --debug src/CouchbaseApplePassRepository.php
/app/src/CouchbaseApplePassRepository.php
 ------ ------------------------------------------------------------------
  Line   CouchbaseApplePassRepository.php
 ------ ------------------------------------------------------------------
  21     Could not read file: [CouchbaseNative]/CouchbaseBucket.class.php
 ------ ------------------------------------------------------------------


 [ERROR] Found 1 error

0.12.1 - 0.12.3

$ phpstan analyse --level=7 --configuration=phpstan.neon --ansi --debug src/CouchbaseApplePassRepository.php
/app/src/CouchbaseApplePassRepository.php
Fatal error: Uncaught PHPStan\ShouldNotHappenException: Internal error. in phar:///composer/vendor/phpstan/phpstan/phpstan/src/Parser/DirectParser.php:27
Stack trace:
#0 phar:///composer/vendor/phpstan/phpstan/phpstan/src/Parser/CachedParser.php(39): PHPStan\Parser\DirectParser->parseFile('[CouchbaseNativ...')
#1 phar:///composer/vendor/phpstan/phpstan/phpstan/src/Type/FileTypeMapper.php(190): PHPStan\Parser\CachedParser->parseFile('[CouchbaseNativ...')
#2 phar:///composer/vendor/phpstan/phpstan/phpstan/src/Type/FileTypeMapper.php(156): PHPStan\Type\FileTypeMapper->createFilePhpDocMap('[CouchbaseNativ...', NULL, NULL)
#3 phar:///composer/vendor/phpstan/phpstan/phpstan/src/Type/FileTypeMapper.php(143): PHPStan\Type\FileTypeMapper->createResolvedPhpDocMap('[CouchbaseNativ...')
#4 phar:///composer/vendor/phpstan/phpstan/phpstan/src/Type/FileTypeMapper.php(61): PHPStan\Type\FileTypeMapper->getResolvedPhpDocMap('[CouchbaseNativ...')
#5 phar:///composer/vendor/phpstan/phpstan/phpstan/src/Reflection/ClassReflection.php(592): PHP in phar:///composer/vendor/phpstan/phpstan/phpstan/src/Parser/DirectParser.php on line 27

0.12.0

$ phpstan analyse --level=7 --configuration=phpstan.neon --ansi --debug src/CouchbaseApplePassRepository.php
/app/src/CouchbaseApplePassRepository.php
Fatal error: Uncaught PHPStan\ShouldNotHappenException: Internal error. in phar:///composer/vendor/phpstan/phpstan/phpstan/src/Parser/DirectParser.php:27
Stack trace:
#0 phar:///composer/vendor/phpstan/phpstan/phpstan/src/Parser/CachedParser.php(39): PHPStan\Parser\DirectParser->parseFile('[CouchbaseNativ...')
#1 phar:///composer/vendor/phpstan/phpstan/phpstan/src/Type/FileTypeMapper.php(198): PHPStan\Parser\CachedParser->parseFile('[CouchbaseNativ...')
#2 phar:///composer/vendor/phpstan/phpstan/phpstan/src/Type/FileTypeMapper.php(164): PHPStan\Type\FileTypeMapper->createFilePhpDocMap('[CouchbaseNativ...', NULL, NULL)
#3 phar:///composer/vendor/phpstan/phpstan/phpstan/src/Type/FileTypeMapper.php(151): PHPStan\Type\FileTypeMapper->createResolvedPhpDocMap('[CouchbaseNativ...')
#4 phar:///composer/vendor/phpstan/phpstan/phpstan/src/Type/FileTypeMapper.php(63): PHPStan\Type\FileTypeMapper->getResolvedPhpDocMap('[CouchbaseNativ...')
#5 phar:///composer/vendor/phpstan/phpstan/phpstan/src/Reflection/ClassReflection.php(592): PHP in phar:///composer/vendor/phpstan/phpstan/phpstan/src/Parser/DirectParser.php on line 27

0.11.19

$ phpstan analyse --level=7 --configuration=phpstan.neon --ansi --debug src/CouchbaseApplePassRepository.php
/app/src/CouchbaseApplePassRepository.php


 [OK] No errors

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