Fix "Differing behaviors when requiring or including relatively vs using __DIR__"#5862
Fix "Differing behaviors when requiring or including relatively vs using __DIR__"#5862staabm wants to merge 12 commits into
Conversation
| if ($expr->left instanceof Node\Scalar\MagicConst\Dir && $expr->right instanceof Node\Scalar\String_) { | ||
| return new Node\Scalar\String_(dirname($scope->getFile()) . $expr->right->value); | ||
| } |
There was a problem hiding this comment.
instead of relying on InitializerExprTypeResolver->getType() to resolve the path based on the global usePathConstantsAsConstantString config, we resolve the path here independently of usePathConstantsAsConstantString, which allows us to report an error for the case in question
| ); | ||
| } | ||
|
|
||
| public function testBug12203NoConstantPath(): void |
There was a problem hiding this comment.
same test as in tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php but without usePathConstantsAsConstantString: true defined via neon-config
| if (file_exists(__DIR__ . '/../vendor/autoload.php')) { | ||
| require __DIR__ . '/../vendor/autoload.php'; | ||
| } |
There was a problem hiding this comment.
in addition to the initial issue, this PR also prevents a error when a given path was checked with file_exists/is_file before require/include
This reverts commit aef3161.
| 5, | ||
| ], | ||
| [ | ||
| 'Path in require_once() "' . __DIR__ . DIRECTORY_SEPARATOR . 'data/../bug-12203-sure-does-not-exist.php" is not a file or it does not exist.', |
There was a problem hiding this comment.
changed the reported error path to the actual expr in the source code, so we don't report a error containing a absolute file path, which cannot be properly used in baselines, because it likely differs between different computers
|
This pull request has been marked as ready for review. |
VincentLanglet
left a comment
There was a problem hiding this comment.
What about something like __DIR__ . $foo . $bar
Might be worth thesting multiple concat
closes phpstan/phpstan#12203