I usually checked this with the following code:
$email = '/[^@:="'s]*@[^@s]*.[a-z]+/iU';
if(preg_match($email,$article->text) == true) {
to something
}
In PHP 8 this is deprecated (Works, but with warning), because I can’t always guarantee that there really is an email in it.
Passing null to parameter #2 ($subject) of type string is deprecated
What are the alternatives?
I know that this solution still works, but I want to be fit for the future.
When searching, I did not find a solution. "str_contains" seems to allow only one string.
2
Answers
It is actually not caused by PHP, but by the Joomla CMS. There are situations where $article->text has not been defined. Thanks to all who have steered mine in the right direction through their thoughts.
First of all, this warning only appears if you enable strict typing (which is a good thing, don’t get me wrong):
It makes more sense to avoid the check altogether:
But, if that isn’t feasible for whatever the reason, you can also default to empty string:
On a side note, PHP has native email validation.