Make WordPress Core

Opened 5 months ago

Closed 5 months ago

#61895 closed defect (bug) (reported-upstream)

null passed to `wp-includes/pomo/po.php` in certain instances when using GlotPress 4.0.1

Reported by: afragen's profile afragen Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.7
Component: I18N Keywords: has-patch dev-feedback php8
Focuses: php-compatibility Cc:

Description

I have a GlotPress installation running WP 6.6.1 and GlotPress 4.0.1. When I look at my debug log it is littered with the following errors.

PHP Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /sites/xxx/files/wp-includes/pomo/po.php on line 270
PHP Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /sites/xxx/files/wp-includes/pomo/po.php on line 271
PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /sites/xxx/files/wp-includes/pomo/po.php on line 127

It is clear that something is passing null into these specific lines. I have added some modified error checking and a cast to alleviate these issues.

Change History (5)

#1 @afragen
5 months ago

  • Focuses php-compatibility added

This ticket was mentioned in PR #7208 on WordPress/wordpress-develop by @afragen.


5 months ago
#2

When running WP 6.6.1 and GlotPress 4.0.1 I have a debug log littered with PHP Warnings

PHP Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /sites/xxx/files/wp-includes/pomo/po.php on line 270
PHP Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /sites/xxx/files/wp-includes/pomo/po.php on line 271
PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /sites/xxx/files/wp-includes/pomo/po.php on line 127

The PR solves these errors by expanding a conditional check and casting a parameter to string.

Trac ticket: https://core.trac.wordpress.org/ticket/61895

#3 @jrf
5 months ago

  • Focuses php-compatibility removed
  • Keywords php81 close added; has-patch php8 removed

@afragen Thanks for reporting this, however the proposed patch is not the way to go as you are hiding errors instead of fixing them.

These functions are all documented to only accept strings, so passing anything else is doing it wrong.

These kind of issue need a backtrace and must be fixed at the source of the problem, i.e. the function calls passing the incorrect data type. They should not be fixed in the receiving functions.

As you mention GlotPress, I suspect the fixes should be made there and that this ticket should be closed as "not a problem with Core".

Version 0, edited 5 months ago by jrf (next)

#4 @dd32
5 months ago

I agree, this should be reported upstream to https://github.com/glotpress/glotpress/ to figure out the bug rather than patching over it. If it turns out to be a core issue, it can be handled back here.

#5 @afragen
5 months ago

  • Focuses php-compatibility added
  • Keywords has-patch php8 added; php81 close removed
  • Milestone Awaiting Review deleted
  • Resolution set to reported-upstream
  • Status changed from new to closed

Reported upstream.

Note: See TracTickets for help on using tickets.