rhubarbgroup / redis-cache

A persistent object cache backend for WordPress powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI.
https://wordpress.org/plugins/redis-cache/
GNU General Public License v3.0
425 stars 148 forks source link

Passing null to parameter results in a warning when running in PHP 8.2.8 #503

Closed sebastianthulin closed 6 months ago

sebastianthulin commented 6 months ago

Description

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/stage/wp-content/object-cache.php on line 2538

Expected Behavior

The subject in the string replacement, should be checked if the type is valid before performing the string replacement. Thus avoiding throwing a warning.

Actual Behavior

A warning is thrown.

Possible Fix

protected function sanitize_key_part( $part ) {

        if( $part === null ) {
            return '';
        }

        return str_replace( ':', '-', $part );
    }

Steps to Reproduce

Shows up randomly.

Additional context

Want the solution to not throw uncecessary errors.

Environment

tillkruss commented 6 months ago

@sebastianthulin: Do you want to open a PR? I'd probably use the null coalescing operator.

sebastianthulin commented 6 months ago

Certainly, I'll take care of that tomorrow. Thank you!

sebastianthulin commented 6 months ago

This seems to have been fixed by you 3 months ago like as follows:

return str_replace( ':', '-', is_scalar( $part ) ? (string) $part : '' );

This enhancement, however, has not yet been incorporated into a released version. Do you plan to make a new release in the near future?

https://github.com/rhubarbgroup/redis-cache/compare/2.5.0...develop

tillkruss commented 6 months ago

Right... I'll tag a version soon.