- Issue created by @hargobind
- Merge request !1Fix PHP 8.1 error with arg(2) containing a null value and being passed to str_replace(). β (Open) created by hargobind
On a site that has contact form categories, visiting a category URL without the subject in the URL causes an error on PHP 8.1.
Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in contact_forms_form_alter() (line 149 of modules/contact_forms/contact_forms.module
Create a contact category called "Test".
Visit http://example.com/contact/Test
That leads to the error:
Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
The problem is on line 149:
$subject = str_replace( $replacement , ' ' , arg(2));
In the example URL above, arg(2) is null because the URL only has the Category name, but not the Subject.
Resolution: Add a null coalescing operator and return an empty string.
$subject = str_replace( $replacement , ' ' , arg(2) ?? '');