Bug #73758 [Nab]: is_dir Drive:Folder returns true - unexpected behavior
| From: | ab@php.net | Date: | Fri, 16 Dec 2016 14:46:36 +0000 |
| Subject: | Bug #73758 [Nab]: is_dir Drive:Folder returns true - unexpected behavior | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-206067@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73758&edit=1
ID: 73758
Updated by: ab@php.net
Reported by: steve dot baldwin at publisure dot com
Summary: is_dir Drive:Folder returns true - unexpected
behavior
Status: Not a bug
Type: Bug
Package: Directory function related
Operating System: Windows 8.1
PHP Version: 5.6.29
Block user comment: N
Private report: N
New Comment:
@steve dot baldwin at publisure dot com, the double backslash comment is related to is_dir, or
actually any function that passes args to the Windows API. But with string parsing functions -
dirname() of c:a\b is c:a, or of c:a\b\c is c:a\b, so that's correct. The path is not supposed
to be resolved in these functions. Improvements to other rare path variant parsing could be done,
yes, however i'm not sure it's a huge issue.
Thanks.
Previous Comments:
------------------------------------------------------------------------
[2016-12-16 14:25:02] steve dot baldwin at publisure dot com
Thats my exact point but thats just a response to a previous comment. I think this ticket should
stay closed however. With PHP7 maybe it will be resolved in the future.
Thanks!
------------------------------------------------------------------------
[2016-12-16 14:12:28] requinix@php.net
dirname, basename, etc. are string processing functions. They do not attempt to resolve the
parameters to actual paths.
------------------------------------------------------------------------
[2016-12-16 13:54:37] steve dot baldwin at publisure dot com
ab@php.net;
Regardless of the escape sequence it will not resolve to the correct path.
var_dump(dirname("C:PHP\Welcome")); #C:PHP
var_dump(dirname("C:PHP\\Welcome")); #C:PHP
var_dump(dirname("C:PHP\\Help\\Me")); #C:PHP\Help
If anything, the escape \ should resolve it to C:PHPelcome.
I am running this directly using CLI so IIS and Apache has no influence on how this is resolved.
------------------------------------------------------------------------
[2016-12-16 13:04:03] ab@php.net
@requinix https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396#fully_qualified_vs._relative_paths
Otherwise yes, not all the path variants are currently supported across PHP implementation.
Thanks.
------------------------------------------------------------------------
[2016-12-16 12:38:05] requinix@php.net
Given that I have a copy of PHP runnable at E:\php56, from the command line:
C:\Windows>E:\php56 -r "var_dump(is_dir('C:Windows'));"
bool(false)
C:\Windows>E:
E:\>E:\php56 -r "var_dump(is_dir('C:Windows'));"
bool(false)
E:\>cd /d C:\
C:\>E:\php56 -r "var_dump(is_dir('C:Windows'));"
bool(true)
C:\>E:
E:\>E:\php56 -r "var_dump(is_dir('C:Windows'));"
bool(true)
Additionally,
E:\>E:\php56 -r "chdir('C:/Windows');
var_dump(is_dir('C:Windows'));"
bool(false)
E:\>E:\php56 -r "chdir('C:/'); var_dump(is_dir('C:Windows'));"
bool(true)
E:\>E:\php56 -r "chdir('C:/Windows'); chdir('E:/');
var_dump(is_dir('C:Windows'));"
bool(false)
E:\>E:\php56 -r "chdir('C:/'); chdir('E:/');
var_dump(is_dir('C:Windows'));"
bool(true)
All of those outputs are correct. I can't easily test is what happens from with IIS or Apache,
but the only change in behavior that I would expect is that C: is always interpreted to be the root
of the drive - "or the drive alone if none is set" clause from that link. But whatever
happens, it is Windows making the decision. At least as far as this code is concerned...
@ab: "Documented scenario"? Where?
That's probably related to this: realpath isn't aware of drive-relative paths.
C:\Windows>E:
E:\>E:\php56 -r "var_dump(is_dir('C:System32'));
var_dump(realpath('C:System32'));"
bool(true)
bool(false)
The bug is the inconsistency. Whether PHP enforces that C:foo is strictly equal to C:\foo or whether
it obeys the rules of the operating system, all of the filesystem functions should work the same
way.
https://github.com/php/php-src/blob/PHP-5.6.29/Zend/zend_virtual_cwd.c#L1260
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=73758
--
Edit this bug report at https://bugs.php.net/bug.php?id=73758&edit=1