PHP 8.1 deprecated passing null to parameter #3 when using str_replace(). str_repace() is commonly used among developers to replace the one word with another in the string.


$value = str_replace( "[", "{", $value );

which replaces [ with { in the string $value.

Since 8.1, if the $value is null, the above deprecated message will be thrown.


Make sure the 3rd parameter is not null.


$value = $value ? str_replace( "[", "{", $value ) : '';

I hope this clarifies! In case you don’t already know, PHP 8.1 also deprecated passing null to parameter #1 of type string in strpos()

[Fix] str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Tagged on:

Sanjeev Aryal

Don't bury your thoughts, put your vision into reality ~ Bob Marley.

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest