Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ jobs:
../../bin/phpstan analyze
- script: |
cd e2e/bug-15102b
composer install
../../bin/phpstan analyze
- script: |
cd e2e/bug-15102
Expand Down
2 changes: 2 additions & 0 deletions e2e/bug-15102b/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
composer.lock
9 changes: 5 additions & 4 deletions e2e/bug-15102b/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php declare(strict_types = 1);

// The shape Illuminate\Foundation\AliasLoader creates: a prepended autoloader that
// resolves a short alias to a real class with class_alias(), reading no file. The alias
// names collide with global functions - Laravel's Cache, File, Str, Hash all do.
require_once __DIR__ . '/src/Real.php';
// The shape Illuminate\Foundation\AliasLoader creates: a prepended autoloader that resolves a
// short alias with class_alias(). The alias names collide with global functions - Laravel's
// Cache, File, Str and Hash all do - and the alias *target* is autoloaded on demand, so the
// class_alias() call is what pulls it in. Nothing is re-included and no function is redeclared.
require __DIR__ . '/vendor/autoload.php';

spl_autoload_register(static function (string $class): void {
if ($class !== 'File') {
Expand Down
7 changes: 7 additions & 0 deletions e2e/bug-15102b/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"autoload": {
"psr-4": {
"E2eFacadeAlias\\": "src/"
}
}
}
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ parameters:
count: 1
path: src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php

-
rawMessage: Creating new ReflectionFunction is a runtime reflection concept that might not work in PHPStan because it uses fully static reflection engine. Use objects retrieved from ReflectionProvider instead.
identifier: phpstanApi.runtimeReflection
count: 1
path: src/Reflection/BetterReflection/SourceLocator/AutoloadFunctionsSourceLocator.php

-
rawMessage: 'Parameter #2 $node of method PHPStan\BetterReflection\SourceLocator\Ast\Strategy\NodeToReflection::__invoke() expects PhpParser\Node\Expr\ArrowFunction|PhpParser\Node\Expr\Closure|PhpParser\Node\Expr\FuncCall|PhpParser\Node\Stmt\Class_|PhpParser\Node\Stmt\Const_|PhpParser\Node\Stmt\Enum_|PhpParser\Node\Stmt\Function_|PhpParser\Node\Stmt\Interface_|PhpParser\Node\Stmt\Trait_, PhpParser\Node\Stmt\ClassLike given.'
identifier: argument.type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PHPStan\Reflection\BetterReflection\SourceLocator;

use Override;
use ReflectionFunction;
use PHPStan\BetterReflection\Identifier\Identifier;
use PHPStan\BetterReflection\Identifier\IdentifierType;
use PHPStan\BetterReflection\Reflection\Reflection;
Expand Down Expand Up @@ -140,11 +141,25 @@ static function () use ($autoloadFunctions, $className): array {
return false;
}

// Only re-including the file that *declares the function of this name* can redeclare it.
// A trapped read of any other file is not the hazard: an aliasing autoloader reads the
// file of the class it aliases to, and that file already being loaded is the normal case -
// class_alias() includes nothing, it names a class that is there. A built-in function has
// no declaring file, so there is nothing it could redeclare.
$functionFileName = (new ReflectionFunction($className))->getFileName();
if ($functionFileName === false) {
return false;
}

// PHP canonicalises the path before it reaches a stream wrapper - a `/./` segment, a
// symlinked directory or an include-path-relative name all arrive resolved - so the
// trapped paths compare directly against get_included_files().
$includedFiles = get_included_files();
foreach ($locatedFiles as $locatedFile) {
if ($locatedFile !== $functionFileName) {
continue;
}

if (in_array($locatedFile, $includedFiles, true)) {
return true;
}
Expand Down