Bug #74589 [Fbk->Csd]: __DIR__ wrong for unicode character

From: Date: Mon, 15 May 2017 16:25:57 +0000
Subject: Bug #74589 [Fbk->Csd]: __DIR__ wrong for unicode character
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209138@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 Updated by: ab@php.net Reported by: ganlvtech at qq dot com Summary: __DIR__ wrong for unicode character -Status: Feedback +Status: Closed Type: Bug Package: *General Issues Operating System: Windows PHP Version: 7.1.5 -Assigned To: +Assigned To: ab Block user comment: N Private report: N New Comment: Thanks for checking. Effectively, PHP 7.1 is a huge rewrite regarding the FS functions and UTF-8 support on Windows in general. Please check also http://git.php.net/?p=php-src.git;a=blob;f=UPGRADING;h=9e23d7a247e0a8f76e1a29f333e08b41237b3d5c;hb=refs/heads/PHP-7.1#l442 Earlier versions use ANSI APIs only so where it can fail parsing - it does. That is a known issue which is likely to be met also on other platforms, fe on systems using some non ASCII multibyte encoding like BIG5, etc. On Windows, this issue is a well known and a long standing issue, so finally was fixed in 7.1 thanks to the wide char APIs. Fe, in PHP < 7.1 there's no support for non ANSI filenames anyway. Still some uncritical or hard to catch places like you've found might be present, so they're being cleaned up all the way. I think i'm just closing the ticket for now. You can still reopen and change to the doc bug, or create a new one or post a doc patch to https://edit.php.net/ . This is however a general behavior in earlier PHP versions, it doesn't concern only __DIR__. Thanks! Previous Comments: ------------------------------------------------------------------------ [2017-05-15 15:22:46] ganlvtech at qq dot com php-7.1-rae3f975 passed the test. But how about php < 7.1 There should be a caution in __DIR__ and dirname() docs. CAUTION! If you are using Windows server and php < 7.1, be sure that all characters in your php script's full path are all ASCII characters. ------------------------------------------------------------------------ [2017-05-15 14:49:45] ab@php.net Finally got the VM, issue confirmed. I've pushed a change in this regard. Any 7.1 or master snapshot starting with ae3f975c5d58f891359a72ad3df84d845e70cdcc is suitable for a test, please fetch one from http://windows.php.net/snapshots/ Thanks. ------------------------------------------------------------------------ [2017-05-15 14:38:05] ab@php.net Automatic comment on behalf of ab Revision: http://git.php.net/?p=php-src.git;a=commit;h=ae3f975c5d58f891359a72ad3df84d845e70cdcc Log: Fixed bug #74589 __DIR__ wrong for unicode character ------------------------------------------------------------------------ [2017-05-15 13:00:10] ganlvtech at qq dot com in ext/standard/string.c:1647 1629 PHP_FUNCTION(dirname) ... 1646 #ifdef PHP_WIN32 1647 ZSTR_LEN(ret) = php_win32_ioutil_dirname(ZSTR_VAL(ret), str_len); 1648 #else 1649 ZSTR_LEN(ret) = zend_dirname(ZSTR_VAL(ret), str_len); 1650 #endif php_win32_ioutil_dirname is used if PHP_WIN32 defined. but in Zend/zend_compile.c:6505 6501 case T_DIR: 6502 { 6503 zend_string *filename = CG(compiled_filename); 6504 zend_string *dirname = zend_string_init(ZSTR_VAL(filename), ZSTR_LEN(filename), 0); 6505 zend_dirname(ZSTR_VAL(dirname), ZSTR_LEN(dirname)); always zend_dirname I'm not very sure about php-src's code structure. It may be a little difficult for me to produce a patch. ------------------------------------------------------------------------ [2017-05-15 10:46:36] ab@php.net Thanks for this deep investigation. Yeah, zend_dirname is what my debug session leads me to. I think that is the exact point. I still couldn't repro this on a cp 437 system, so I'm getting a VM with cp 936, might take some time. If you're able to debug internals or even produce a patch, i can also evaluate/test that. Basically, there's only 7.1 with UTF-8 support and versions before. To the time of the initial patch, I explicitly left zend_dirname() as is and instead integrated the new API, fe like in the userland dirname(). The only point in the new API is, that it needs the INI to have been initialized before. So might need to check this and reevaluate, if everything is ok, then just replace zend_dirname to use the new API for Windows. Thanks. ------------------------------------------------------------------------ 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=74589 -- Edit this bug report at https://bugs.php.net/bug.php?id=74589&edit=1

« previous php.bugs (#209138) next »