simple-lightbox
simple-lightbox copied to clipboard
PHP 8.1: Passing `null` to non-nullable parameters of built-in functions
Description of Problem
PHP deprecation message:
PHP Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in xxxxxxxxxxxxxxxx\wp-content\plugins\simple-lightbox\includes\class.utilities.php on line 545
In the WP.org support post you mentioned this seemed like a configuration problem, because null
shouldn't be what gets passed around there. But you do have code explicitly setting this var to null
in some scenarios. I've added some comments to the below source code identifying such instances:
function extend_client_object( $obj, $data = null, $out = false ) {
// Validate parameters
$args = func_get_args();
switch ( count( $args ) ) {
case 2:
if ( ! is_scalar( $args[0] ) ) {
if ( is_bool( $args[1] ) ) {
$out = $args[1];
}
} else {
break;
}
// no break.
case 1:
// HERE
$data = $args[0];
$obj = null;
break;
}
// Default client object
if ( ! is_string( $obj ) || empty( $obj ) ) {
// AND HERE
$obj = null;
}
// Default data
if ( is_array( $data ) ) {
$data = (object) $data;
}
// Build expression
if ( empty( $data ) || ( empty( $obj ) && is_scalar( $data ) ) ) {
$ret = '';
} else {
$c_obj = $this->get_client_object( $obj );
// Then it's passed to `validate_client_object`, which is where it gets passed to `trim` in such a way that PHP 8.1 doesn't like.
$ret = $this->validate_client_object( $obj, sprintf( '{$.extend(%1$s, %2$s);}', $c_obj, wp_json_encode( $data ) ) );
if ( $out ) {
// so on and so forth
Maybe that could either default to something valid for the call to trim
or short-circuit or...idk. Something else.
Details
- URL of Page exhibiting problem: dev environment, but message is appearing at bottom of admin pages and front-end pages
- Browser(s) exhibiting problem (Firefox, Chrome, etc.): Firefox
- Version of SLB Installed: 2.9.3
- Other plugins installed:
+---------------------------------+----------+--------+---------+
| name | status | update | version |
+---------------------------------+----------+--------+---------+
| advanced-custom-fields-pro | active | none | 6.1.4 |
| sterner-stuff-barncraft | active | none | |
| easy-notification-bar | inactive | none | 1.4.5 |
| font-awesome | active | none | 4.3.2 |
| gravityforms | active | none | 2.7.4 |
| gravityformscli | active | none | 1.4 |
| gravityformspartialentries | active | none | 1.7 |
| gravity-forms-zero-spam | active | none | 1.4 |
| gutenberg | active | none | 15.6.2 |
| mailgun | active | none | 1.9.3 |
| redirection | active | none | 5.3.10 |
| safe-svg | active | none | 2.1.1 |
| simple-lightbox | active | none | 2.9.3 |
| google-site-kit | active | none | 1.99.0 |
| stream | active | none | 3.9.3 |
| tiny-compress-images | active | none | 3.4.1 |
| wp-crontrol | active | none | 1.15.2 |
| wp-migrate-db-pro | active | none | 2.6.5 |
| amazon-s3-and-cloudfront-pro | active | none | 3.2.1 |
| wp-rocket | active | none | 3.13.1 |
| wordpress-seo | active | none | 20.6 |
| zero-spam | active | none | 5.4.4 |
| bedrock-autoloader | must-use | none | 1.0.3 |
| wp-migrate-db-pro-compatibility | must-use | none | 1.3 |
| advanced-cache.php | dropin | none | |
+---------------------------------+----------+--------+---------+