[wp-trac] [WordPress Trac] #59154: PHP Deprecated: ltrim():

WordPress Trac noreply at wordpress.org
Thu Sep 28 21:24:51 UTC 2023


#59154: PHP Deprecated:  ltrim():
-------------------------------------------------+-------------------------
 Reporter:  codersantosh                         |       Owner:
                                                 |  hellofromTonya
     Type:  defect (bug)                         |      Status:  closed
 Priority:  normal                               |   Milestone:  6.4
Component:  General                              |     Version:  6.3
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests has-        |     Focuses:  php-
  testing-info commit                            |  compatibility
-------------------------------------------------+-------------------------
Changes (by hellofromTonya):

 * status:  reviewing => closed
 * resolution:   => fixed


Comment:

 In [changeset:"56740" 56740]:
 {{{
 #!CommitTicketReference repository="" revision="56740"
 Code Modernization: Fix "passing null to non-nullable" deprecation from
 next_posts().

 The `esc_url()` function expects to a string for `$url` parameter. There
 is no input validation within that function. The function contains a
 `ltrim()` which also expects a string. Passing `null` to this parameter
 results in `Deprecated: ltrim(): Passing null to parameter #1 ($string) of
 type string is deprecated` notice on PHP 8.1+.

 Tracing the stack back, a `null` is being passed to it within
 `next_posts()` when `get_next_posts_page_link()` returns `null` (it can
 return a string or `null`).

 On PHP 7.0 to PHP 8.x, an empty string is returned from `esc_url()` when
 `null` is passed to it. The change in this changeset avoids the
 deprecation notice by not invoking `esc_url()` when
 `get_next_posts_page_link()` returns `null` and instead sets the `$output`
 to an empty string, thus maintain the same behavior as before (minus the
 deprecation notice).

 Adds a test to validate an empty string is returned and the absence of the
 deprecation (when running on PHP 8.1+).

 Follow-up to [11383], [9632].

 Props codersantosh, nihar007, hellofromTonya, mukesh27, oglekler,
 rajinsharwar.
 Fixes #59154.
 }}}

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


More information about the wp-trac mailing list