Unicode Code Point Escape Syntax
As we have previously pointed out, PHP is notoriously bad at
supporting UTF-8 or Unicode in general, at least with regard to its
internal functions. Aside from the functions provided by the
iconv
and mbstring
extensions, PHP is
oblivious of any encoding.
This is particularly annoying when it comes to all the Unicode special chars and control codes that affect formatting. If they are part of the actual source code any Unicode aware editor or IDE would honor them – and potentially render the source code unreadable.
To address this and to close the gap to other programming languages that already have a similar feature, PHP 7 now supports Unicode escape sequences within double quoted strings. When executed, this code would output an Unicode smiley on supporting terminals:
echo "\u{1F602}";
As a result of this addition, strings containing \u{
followed by an invalid sequence will now trigger an error. Strings
that merely contain \u
are not affected.