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 |
`$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 :) |
amieiro
left a comment
There was a problem hiding this comment.
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.
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