Make WordPress Core

#58275 closed defect (bug) (invalid)

PHPv81 preg_split deprecation error in convert_smilies function

Reported by: joostdekeijzer's profile joostdekeijzer Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.3
Component: Formatting Keywords: has-patch php81
Focuses: Cc:

Description

Running PHP 8.1 I get the following error:

[09-May-2023 10:23:57 UTC] PHP Deprecated: preg_split(): Passing null to parameter #2 ($subject) of type string is deprecated in /wp-includes/formatting.php on line 3442

A solution might be to test on the $text argument not being empty? But when I do that I get a followup error:

[09-May-2023 10:30:55 UTC] PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /wp-includes/formatting.php on line 3906

(in wp_trim_excerpt).

Attachments (1)

58275.patch (673 bytes) - added by joostdekeijzer 18 months ago.
Fixes convert_smilies issue but not followup issue

Download all attachments as: .zip

Change History (6)

@joostdekeijzer
18 months ago

Fixes convert_smilies issue but not followup issue

#1 @joostdekeijzer
18 months ago

  • Keywords has-patch added

#2 @SergeyBiryukov
18 months ago

  • Keywords php81 added

#3 @jrf
18 months ago

@joostdekeijzer Thanks for reporting this. This needs a backtrace to see where the error originates from.

The convert_smilies() function is clearly marked as only accepting string values for $text.

The current proposed patch would widen the parameter type to ?string and hide the error instead of fixing it.

This should be fixed in the location where null is being passed to convert_smilies() instead.

#4 @joostdekeijzer
18 months ago

@jrf as suggested I backtraced the issue to a thirdparty plugin (Visual Composer v6.11.0).

Sorry I did not do this earlier.

Contemplating on how I'd expect the function to handle invalid input and I think I'd expect a function to handle this gracefully?

Although I can imagine this issue to be closed as "invalid" since a third party plugin creates the issue...

#5 @jrf
18 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

@joostdekeijzer Thanks for doing that and I hope they will fix it soon/accept a patch for it.

Those PHP notices are there for a reason and WP should not be hiding them ("handling them gracefully") as that would hide important information for devs to allow them to fix their plugins.

Note: See TracTickets for help on using tickets.