Skip to content
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

PHP 8.1: Passing null to non-nullable parameters of built-in functions #1008

Open
ethanclevenger91 opened this issue Apr 28, 2023 · 2 comments
Labels
compat:php PHP compatibility support

Comments

@ethanclevenger91
Copy link

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

image

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   |         |
+---------------------------------+----------+--------+---------+
@ethanclevenger91
Copy link
Author

I have a guess that this could be related to images that 404, by the way. This is a local environment where I haven't pulled down all the images from production. A 404 should fail gracefully - the deprecation indicates that the way this is written, images that 404 may trigger a fatal in PHP 9+

@archetyped
Copy link
Owner

Thank you for the additional details.

@archetyped archetyped added the compat:php PHP compatibility label May 3, 2023
@archetyped archetyped changed the title PHP 8.1 deprecation PHP 8.1: Passing null to non-nullable parameters of built-in functions May 3, 2023
@archetyped archetyped changed the title PHP 8.1: Passing null to non-nullable parameters of built-in functions PHP 8.1: Passing null to non-nullable parameters of built-in functions May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compat:php PHP compatibility support
Projects
None yet
Development

No branches or pull requests

2 participants