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.0 warning thrown by normalize_parameters #223

Closed
szaqal83 opened this issue Dec 16, 2020 · 8 comments · Fixed by #226
Closed

PHP 8.0 warning thrown by normalize_parameters #223

szaqal83 opened this issue Dec 16, 2020 · 8 comments · Fixed by #226

Comments

@szaqal83
Copy link

After switching from PHP 7.4 to 8.0 a warning is thrown:

[16-Dec-2020 10:43:09 UTC] PHP Warning: WP_REST_OAuth1::normalize_parameters(): Argument #2 ($value) must be passed by reference, value given in /.../wp-content/plugins/rest-api-oauth1/lib/class-wp-rest-oauth1.php on line 672

@szaqal83
Copy link
Author

szaqal83 commented Dec 29, 2020

Proper callback should look like this:

protected function normalize_parameters( &$value, $key ) { // $key = self::urlencode_rfc3986( rawurldecode( $key ) ); // doesn't make any effect $value = self::urlencode_rfc3986( rawurldecode( $value ) ); }

@scottfennell-toptal
Copy link

Are you sure you have the params in the correct order? Previously, it was $key first, $value second:

https://github.com/WP-API/OAuth1/blob/master/lib/class-wp-rest-oauth1.php#L754

@szaqal83
Copy link
Author

szaqal83 commented Aug 26, 2022

Params order is fine, normalize_parameters is called here:
/.../wp-content/plugins/rest-api-oauth1/lib/class-wp-rest-oauth1.php on line 672

array_walk_recursive( $params, array( $this, 'normalize_parameters' ) );

according to PHP docs https://www.php.net/manual/en/function.array-walk-recursive.php:
"Typically, callback takes on two parameters. The array parameter's value being the first, and the key/index second."

So declaration of normalize_parameters function in:
/.../wp-content/plugins/rest-api-oauth1/lib/class-wp-rest-oauth1.php on line 754
has wrong params order, it is:

protected function normalize_parameters( &$key, &$value ) { ... }

it should:

protected function normalize_parameters( &$value, $key ) { ... }

also there's no need to pass $key by reference and normalize it because any $key changes won't be made in array.

@scottfennell-toptal
Copy link

scottfennell-toptal commented Aug 26, 2022

But if you change the order of the params in the function definition, don't you need to also change their order when calling the function?

Maybe in this case you don't, because of the way array_walk_recursive() works, but I can't quite make out why. The code is a bit overly clever :D

@szaqal83
Copy link
Author

No you don't need to change order of params passed because there is only one param ($params is an array).

@scottfennell-toptal
Copy link

Thank you for the response. It makes sense now.

As an aside -- I still use and depend on this plugin heavily. Obviously it is completely abandoned. I don't understand what the replacement for it was. Do you?

@szaqal83
Copy link
Author

@szaqal83
Copy link
Author

Will there be an update here: https://wordpress.org/support/plugin/rest-api-oauth1/ ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants