php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76897 PHP CLI accepts only basic ASCII characters on STDIN
Submitted: 2018-09-17 19:22 UTC Modified: 2018-09-18 15:13 UTC
From: giacobbe_85 at tiscali dot it Assigned: cmb (profile)
Status: Not a bug Package: *Unicode Issues
PHP Version: 7.1.22 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
47 - 8 = ?
Subscribe to this entry?

 
 [2018-09-17 19:22 UTC] giacobbe_85 at tiscali dot it
Description:
------------
*** Test conditions: 
Windows 10 Home 64 bit
Windows 7 Pro 64 bit
Command line charsets: cp850, cp1252, cp65001

*** PHP Version tested:
All PHP 7.2.10 versions (x64 / x86, thread safe / non thread safe)
All PHP 7.1.22 versions (x64 / x86, thread safe / non thread safe)

*** Symptoms
When executed from command line, PHP interpreter only accepts from STDIN characters with decimal code smaller than 127 of the current charset. All characters with a bigger code will be read as 0. In other words, no special character can be inputed on the command line, except the basic ASCII ones. If a special character (accented, umlauts, etc) is typed, it will be NULL.

The problem is not present if older versions of PHP are used, like PHP 7.0.32 Win32 VC14 x64 or PHP 5.x

Test script:
---------------
<?PHP

// Read string contains end line chars
$s = fgets(STDIN);
echo bin2hex($s);

// Read string doesn't contain end line chars
$s = stream_get_line(STDIN, 999999, PHP_EOL);
echo bin2hex($s);

?>

Expected result:
----------------
If, for example, the user inputs the "ò" and "à" characters, the CLI output should be (assume cp850 as charset):

ò
950d0a
à
85

Actual result:
--------------
If, for example, the user inputs the "ò" and "à" characters, the CLI output is:

ò
000d0a
à
00

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-18 15:13 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2018-09-18 15:13 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

As of PHP 7.1.0 you need to set the internal_encoding properly
for this to work.  For details see
<http://php.net/manual/en/migration71.windows-support.php#migration71.windows-support.long-and-utf8-path>.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Apr 02 10:01:23 2020 UTC