peachpiecompiler / peachpie

PeachPie - the PHP compiler and runtime for .NET and .NET Core
https://www.peachpie.io
Apache License 2.0
2.33k stars 202 forks source link

function strlen should be the byte count of the string #1041

Open avriltank opened 2 years ago

avriltank commented 2 years ago

For example: strlen("张三") //should be 6,php code Encoding.Default.GetByteCount("张三")

if we edit the code of peachpie,there are many functions should be edited,such as "strpos","strrpos","fread"....

jakubmisek commented 2 years ago

You are right, in general, there are some incompatibilities.

We have tried to make PHP Unicode safe and to take advantage of the .NET native String (UTF-16) type.

There are some known exceptions described at https://docs.peachpie.io/php/unicode/

Wherever you need to treat the value as 8-bit string, you can cast it using (binary) operator, e.g.:

strlen( (binary)"张三" );

Currently, this is a known behavior, and basically, we are still evaluating what would be the right approach.