phpstan: PHPStan does not work with UNC paths on Windows
Bug report
PHPStan version: 0.12.32
I am running a CentOS 7 instance using Windows Subsystem for Linux (WSL) on my Windows 10 PC. I accesses the CentOS 7 files using a UNC:
\wsl$\CentOS7\my\files\here (which provides access to /my/files/here in the Linux file system)
It seems that UNC paths are unsupported. See next section.
Code snippet that reproduces the problem
I tested by running the following at a command prompt in my C:\Users\me folder:
phpstan analyze \\wsl$\CentOS7\my\files\here\blah.php
Which provided the following error message:
Path C:\Users\me\wsl$\CentOS7\my\files\here\blah.php does not exist
I tested to ensure it does exist with our favorite built-in Windows command:
dir \\wsl$\CentOS7\my\files\here\
Which provided the list of files:
Volume in drive \\wsl$\CentOS7 has no label.
Volume Serial Number is 0000-0000
Directory of \\wsl$\CentOS7\var\www\TDEV\import\shared
07/01/2020 10:26 AM <DIR> .
07/01/2020 10:26 AM <DIR> ..
07/01/2020 10:51 AM 4,284 blah.php
1 File(s) 4,284 bytes
2 Dir(s) 107,505,917,952 bytes free
Expected output
I would have expected that phpstan would have happily analyzed blah.php just as it would have if the file was on a local drive such as C:.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 38 (11 by maintainers)
This has nothing to do with
"or'or\\\. The problem is that PHPStan doesn’t know that path starting with\\is an absolute path, and tries to expand it to an absolute path, that’s why it shows the message:Path C:\Users\me\wsl$\CentOS7\my\files\here\blah.php does not existdescribed in the OP. And there might be other assumptions that wouldn’t work with these paths.This might be a code bug due to the way PHP handles strings in quotes vs. double-quotes, but I have no idea why it only occurs on mapped drives rather than local drives like C:.
Here’s a test PHP script called
tryfile.php:It bombs because of the way the backslashes are handled in double-quoted strings:
I swapped out the double quotes for single quotes:
And it works fine: C:\Temp\x>php tryfile.php