`require_once` file existence check doesn't account for `chdir`.
Author: ssigwartCreated Sep 17, 2026Updated Sep 17, 2026
Labelsfeature-request
Bug report
require_once doesn't account for chdir. Something like this will cause an error even if ../config.php exists:
chdir('..');
require_once('config.php');Path in require_once() "constants.php" is not a file or it does not exist.Note that the code snipped will fail because the file probably doesn't actually exist in the sandbox either.
Code snippet that reproduces the problem
https://phpstan.org/r/24b920ed-6231-4278-b401-c3747ccce06f
Expected output
It shouldn't report the file as non-existent.
I wonder if https://github.com/phpstan/phpstan-src/blob/2.3.x/src/File/IncludedFilePathResolver.php can parse any chdir in the current file and add those directories to the list of allowed directories here. Obviously, it's not feasible to check for chdir in any file, but the current file seems reasonable to do.
Did PHPStan help you today? Did it make you happy in any way?
Yes. It gives me a lot more confidence that code is okay when reviewing it. Thanks!
Source: phpstan/phpstan