New value type (null) is not matching the resolved parameter type code example
Example: New value type (null) is not matching the resolved parameter type
preg_replace can return 'string|string[]|null', hence the warning is there.
What about $text = (string) preg_replace(...)
(you are not handling null-value anyway)