abertschi / graalphp

An efficient PHP implementation built on GraalVM
https://abertschi.ch/blog/2020/building-graalphp/
Apache License 2.0
289 stars 13 forks source link

string implementation #69

Open solidpulse opened 4 years ago

solidpulse commented 4 years ago

I thought implementing string would be easy, but I was so wrong, [https://github.com/avierr/graalphp/commit/58142efd3c8e3e65ac1be93d21edea32c35c9810]

PHP supports string interpolation, probably this needs some pre-processing to convert it into string concatenation operations?

we know Java uses strings that are utf16 encoded. strings in PHP are also used to store binary data, I went ahead and did some research on how others handle this,

1.PeachPie https://github.com/peachpiecompiler/peachpie/blob/master/src/Peachpie.Runtime/PhpString.cs

2.JPHP https://github.com/jphp-group/jphp/blob/master/jphp-runtime/src/php/runtime/memory/StringMemory.java

3.HippyVM https://github.com/hippyvm/hippyvm/blob/master/hippy/objects/strobject.py

4.Tagua-vm https://github.com/tagua-vm/tagua-vm (not sure how this works)

other challenges: implicit casting rules that PHP has to convert strings to numbers and vis versa. https://php.net/manual/en/language.types.type-juggling.php

Most of this is way out of my league, so I don't have any opinions on this, let me if anyone has any thoughts on which direction to proceed in

Girgias commented 4 years ago

Note: the behaviour of numeric string is changing in PHP 8: https://wiki.php.net/rfc/saner-numeric-strings

The php spec repo hasn't been updated yet.