Invalid UTF-8 codepoint escape

Description

PHP supports unicode as escape sequence. They are used in double-quoted strings, and use the \u{73} format. The digits must represent a valid unicode codepoint: here, 73 represents the ASCII letter s.

When the prefix \u{ is detected, PHP tries to understand the next characters as an integer. When this is not the case, it fails the codepoint detection and stops.

In particular, it is not possible to use the _ number separator in these sequences.

Example

<?php

    $a = "\u{fgh}";

    echo \u{1F4_18};

?>

Solutions

  • Check the values inside the curly braces: chances are it needs to be replaced with smaller values.

  • If there is no intent to use unicode codepoint, add \ to make PHP handle it as a literal value.

See Also