-
Notifications
You must be signed in to change notification settings - Fork 129
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
Avoid passing null
to trim()
#1698
Conversation
Hi @swissspidy Using PHP8.2 (I think we have the same warning with PHP8.1) I was able to reproduce the first issue in the
But I couldn't reproduce the problem in the |
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.
Thank you!
`$status` can be `null`
All those errors occurred after setting up GlotPress on a fresh install and then creating a new project and importing originals + translations. I actually just found a third one this way. |
We could find even more if we add PHPStan testing :) |
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.
I was able to reproduce these 3 problems when I create a new project, import its originals and did one translation:
PHP Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /wordpress/glotpress2/wp-content/plugins/GlotPress/gp-includes/thing.php on line 689
PHP Deprecated: mb_strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /Users/amieiro/code/wordpress/glotpress2/wp-content/plugins/GlotPress/gp-includes/things/original.php on line 215
PHP Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /wordpress/glotpress2/wp-content/plugins/GlotPress/gp-templates/helper-functions.php on line 416
After apply this PR, I didn't get the errors, so it is ok for me.
if ( ! $entry->context ) { | ||
$entry->context = ''; | ||
} |
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.
This introduced a bug, see #1724. This should better be solved by checking for is_string()
before calling mb_strlen()
.
Problem
I got some PHP deprecation notices:
Solution
Set variable to an empty string if null.
To-do
Testing Instructions
Screenshots or screencast