Bug #74589 [Com]: __DIR__ wrong for unicode character

From: Date: Sun, 14 May 2017 17:52:31 +0000
Subject: Bug #74589 [Com]: __DIR__ wrong for unicode character
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209108@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74589&edit=1 ID: 74589 Comment by: ganlvtech at qq dot com Reported by: ganlvtech at qq dot com Summary: __DIR__ wrong for unicode character Status: Feedback Type: Bug Package: *General Issues Operating System: Windows PHP Version: 7.1.5 Block user comment: N Private report: N New Comment: php.ini is php.ini-development default_charset => UTF-8 => UTF-8 internal_encoding => no value => no value zend.multibyte => Off => Off PHP version: PHP 7.1.5 (cli) (built: May 9 2017 19:48:36) ( NTS MSVC14 (Visual C++ 2015) x64 ) System: Windows 10 Home (64bit). (x64 processor) Default language: zh-CN (There is no other system language supported in my system. My system cannot switch into English mode) Default code page: 936(GBK) I tried chcp 65001 or chcp 437, it makes no changes. ===== I have tried in Interactive shell. It seems working correctly. D:\新建文件夹>php -a Interactive shell php > echo __FILE__; php shell code php > echo __DIR__; D:\新建文件夹 ===== I have also tried php 5.4 or php 5.6 (both are use php.ini-development) "D:\新建文件夹\test.php" shows (different from php7) D:\ D:\ bool(true) So, i tried Script: <?php echo __DIR__, "\n"; echo dirname(__FILE__), "\n"; var_dump(__DIR__ === dirname(__FILE__)); echo __FILE__, "\n"; echo str_replace('\\', '/', __FILE__), "\n"; echo dirname(str_replace('\\', '/', __FILE__)), "\n"; ?> Result: (php 5.4) D:\ D:\ bool(true) D:\新建文件夹\test.php D:/新建文件夹/test.php D:/新建文件夹 ===== Anything works well on Ubuntu Server 16.04 (php7.0 and php5.5 were tested). I think it may be caused by backslash. Previous Comments: ------------------------------------------------------------------------ [2017-05-14 14:37:47] ab@php.net Thanks for the report. Please post additionally - default_charset INI - internal_encoding INI - whether zend_multibyte is used - whether your're on a DBCS system, codepage 932, 936 or alike I have to say, that so far i've tried the snippet on a cp 437 system with default php.ini settings, i see it working correctly. I guess, that there can be an issue with a particular system codepage and non UTF-8 settings in php.ini, would be nice you to do a bit more research in this direction. Thanks. ------------------------------------------------------------------------ [2017-05-14 07:07:24] ganlvtech at qq dot com Description: ------------ Save the test script to "D:\新建文件夹\test.php".(There must be some unicode character in the path) Then execute php test.php. On Windows, shows D:\ D:\新建文件夹 bool(false) Save to "D:\新建文件夹a\test.php", then shows D:\新建文件夹a D:\新建文件夹a bool(true) Save to "D:\a新建文件夹\test.php", then shows D:\ D:\a新建文件夹 bool(false) Save to "D:\a新建文件夹\a新建文件夹\test.php", then shows D:\ D:\a新建文件夹\a新建文件夹 bool(false) So, you may find that. If the directory's name ends with a unicode character, then __DIR__ would miss this part, until it find a dir not ends with a unicode character. Sorry for my poor English. Test script: --------------- <?php echo __DIR__, "\n"; echo dirname(__FILE__), "\n"; var_dump(__DIR__ === dirname(__FILE__)); ?> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74589&edit=1

« previous php.bugs (#209108) next »