[wp-trac] [WordPress Trac] #55603: PHP 8.2: address deprecation of the utf8_encode() and utf8_decode() functions

WordPress Trac noreply at wordpress.org
Thu Mar 21 15:46:27 UTC 2024


#55603: PHP 8.2: address deprecation of the utf8_encode() and utf8_decode()
functions
-------------------------------------------------+-------------------------
 Reporter:  jrf                                  |       Owner:
                                                 |  hellofromTonya
     Type:  task (blessed)                       |      Status:  assigned
 Priority:  normal                               |   Milestone:  6.6
Component:  General                              |     Version:  6.0
 Severity:  normal                               |  Resolution:
 Keywords:  2nd-opinion php82 dev-feedback has-  |     Focuses:  coding-
  patch has-unit-tests                           |  standards
-------------------------------------------------+-------------------------

Comment (by SergeyBiryukov):

 In [changeset:"57861" 57861]:
 {{{
 #!CommitTicketReference repository="" revision="57861"
 Tests: Remove unnecessary use of `utf8_encode()` in KSES tests.

 One of the tests for the `wp_kses_xml_named_entities()` function used
 `utf8_encode( chr( 160 ) )` to set an expectation of a Unicode character
 for a non-breaking space.

 It is understandable that this expectation was previously set this way, as
 it is not possible for a developer to distinguish between a ''breaking''
 space and a ''non-breaking'' space visually, so the chances of the test
 accidentally breaking on an incorrect save when the plain Unicode
 character would be used, was high.

 However, the `utf8_encode()` function is deprecated as of PHP 8.2, and its
 use needs to be removed from the WP codebase.

 PHP 7.0 has introduced [https://wiki.php.net/rfc/unicode_escape Unicode
 escape sequences], which allows to create a text string using Unicode
 characters referenced by their codepoint. By switching the test case to
 provide the test expectation using a Unicode escape sequence, we remove
 the use of the deprecated PHP function and still preserve the safeguard
 against the test accidentally breaking.

 Follow-up to [52229].

 Props jrf, afercia, poena, SergeyBiryukov.
 See #55603, #60705.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55603#comment:69>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list