-
-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed strip_tags(): Passing null to parameter #1 in Fulltext.php #3655
Fixed strip_tags(): Passing null to parameter #1 in Fulltext.php #3655
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this change solves the deprecation error it also changes the result of the code.
See this following example:
Currently in PHP 8.1/8.2 the deprecation is thrown but the built-in methods behave as before, so the result of strip_tags(null)
is empty string, not null. Subsequently in cases where $value
is null in line 764 it currently becomes empty string after this line is executed. With your change $value
stays null when returning in line 768.
For BC sake and to avoid unforeseen consequences, I would therefore propose to set $value
to empty string in the else branch of the condition:
if ($value !== null) {
$value = preg_replace("#\s+#siu", ' ', trim(strip_tags($value)));
} else {
$value = '';
}
@kiatng i'd change it a bit to guarantee work with strict types turned on simple: cast to string
or more strict:
or:
|
From googling, the idea of declaring strict typing is to get PHP to throw errors early on so that bugs can be avoided. I get it if it's a new class that we are coding. But for existing classes, doing something like $value = preg_replace("#\s+#siu", ' ', trim(strip_tags((string)$value))); seems to me, defeats the purpose of catching the bugs early on. Strict typing is bypassed, the directive is ignored. So, I would argue that this is better: $value = $value === null ? '' : preg_replace("#\s+#siu", ' ', trim(strip_tags($value))); Let PHP throws the error when we have this Taking a step back, is there a compelling reason to insert |
I dont like casting to In case of scalar value casting is pretty safe. |
I'm working on this, b/c it seems to be a large benefit for better code - even if we do not have typed parameters/returns. |
Description (*)
In the process of updating a couple of sites to PHP8.1. This was logged: