Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 30, 2019

Unicode codepoint escape syntax

This takes a Unicode codepoint in hexadecimal form, and outputs that codepoint in UTF-8 to a double-quoted string or a heredoc. Any valid codepoint is accepted, with leading 0's being optional.

echo "\u{aa}";
echo "\u{0000aa}";
echo "\u{9999}";

\u{ may cause errors ¶

Due to the addition of the new Unicode codepoint escape syntax, strings containing a literal \u{ followed by an invalid sequence will cause a fatal error. To avoid this, the leading backslash should be escaped.

Refs:

Includes unit tests.

Implementation notes

  1. This introduces a new sniff category TextStrings.
  2. This adds a new Sniff::getCompleteTextString() utility method to get all parts of a multi-line text string.
    This method is a duplicate of a new utility method which will be introduced in PHPCS 3.5.0.
    The upstream version is accompanied by plenty of unit tests.

jrfnl added 2 commits July 30, 2019 04:19
... to get all parts of a multi-line text string.

This method is a duplicate of a new utility method which will be introduced in PHPCS 3.5.0.

The upstream version is accompanied by plenty of unit tests.
> ### Unicode codepoint escape syntax
>
> This takes a Unicode codepoint in hexadecimal form, and outputs that codepoint in UTF-8 to a double-quoted string or a heredoc. Any valid codepoint is accepted, with leading 0's being optional.
> ```php
> echo "\u{aa}";
> echo "\u{0000aa}";
> echo "\u{9999}";
> ```

> ### `\u{` may cause errors ¶
>
> Due to the addition of the new Unicode codepoint escape syntax, strings containing a literal `\u{` followed by an invalid sequence will cause a fatal error. To avoid this, the leading backslash should be escaped.

Refs:
* https://wiki.php.net/rfc/unicode_escape
* https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.unicode-codepoint-escape-syntax
* https://www.php.net/manual/en/migration70.incompatible.php#migration70.incompatible.strings.unicode-escapes
* php/php-src@bae46f3

Includes unit tests.
@jrfnl jrfnl added this to the 9.3.0 milestone Jul 30, 2019
@jrfnl jrfnl requested a review from wimg July 30, 2019 02:48
@wimg wimg merged commit 9d844d1 into master Aug 28, 2019
@delete-merged-branch delete-merged-branch bot deleted the php-7.0/new-unicode-escape-sniff branch August 28, 2019 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.