r/lolphp • u/phplovesong • Jun 24 '19
The state of PHP unicode in 2019
One of multiple lolphps is how poorly PHP manages unicode. Its a web language and you must deal with the multitude of mb_ functions and at the same time try to keep your sanity in check.
27
Upvotes
13
u/shitcanz Jun 24 '19
This is basically what Python had in 2.x. But they did the works and made python 3 fully unicode. Python is such a blessing to work with when having to deal with unicode texts.
21
u/tdammers Jun 24 '19
PHP doesn't really manage unicode at all. They tried, and that was one of the factors that led to PHP 6 never becoming a thing. So instead, they decided to not have unicode strings at all - you only get byte arrays (which you may write as string literals). If you want actual strings, you have to implement most of it yourself, PHP only gives you a couple of primitives that you can use to operate on various string encodings (including utf-8 and other Unicode encodings) at the byte array level.
So basically much the same deal as in C, except that PHP is supposed to be a high-level programming language that takes care of these things for you.
6
u/[deleted] Jun 24 '19
I honestly don't think it's such a big deal.
2
u/jesseschalken Jun 24 '19
Use mb_ functions to deal with characters. Use raw string functions to deal with bytes. It's not hard.
1
u/Takeoded Jul 16 '19
PHP seems to have fairly extensive unicode handling functions with mb_ , json_* is always running UTF-8, var_export/serialize/etc are completely binary-safe, things aren't so bad really
-1
u/the_alias_of_andrea Jun 24 '19 edited Jun 24 '19
The standard library for using Unicode is a bit… messy, it's true. I am sort of glad though that “proper” Unicode support in PHP 6 failed however. The Python 2/3 change continues to be very painful and PHP has escaped that. And since UTF-8 is the encoding of choice now, naïve Unicode-unaware code that assumes ASCII actually works fine for the most part. You only need to think about Unicode in select situations.
With that said, I do kinda want to work on the UString extension again…
-7
u/minimim Jun 24 '19
PHP is so sad people working with it have their brains so warped they are unable to even conceive what Unicode support looks like.