wordpress-seo
wordpress-seo copied to clipboard
PHP deprecated notice
- [x] I've read and understood the contribution guidelines.
- [x] I've searched for any related issues and avoided creating a duplicate issue.
Please give us a description of what happened
To Reproduce
Step-by-step reproduction instructions
- When using PHP 8.1 with Yoast SEO 22.9, the debug log shows
PHP Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /wp-content/plugins/wordpress-seo/src/presenters/canonical-presenter.php on line 49
Screenshots, screen recording, code snippet
If possible, please provide a screenshot, a screen recording or a code snippet which demonstrates the bug.
Technical info
- If relevant, which editor is affected (or editors):
- [ ] Block Editor
- [ ] Gutenberg Editor
- [ ] Elementor Editor
- [ ] Classic Editor
- [ ] Other:
- Which browser is affected (or browsers):
- [x] Chrome
- [ ] Firefox
- [ ] Safari
- [ ] Other:
Used versions
- Device you are using:
- Operating system:
- PHP version: 8.1.28
- WordPress version: 6.5.4
- WordPress Theme: Hello Elementor
- Yoast SEO version: 22.9
- Gutenberg plugin version:
- Elementor plugin version:
- Classic Editor plugin version:
- Relevant plugins in case of a bug:
Please inform the customer of conversation # 1148586 when this conversation has been closed.
Please include this customer of conversation # 1174638 when this conversation has been closed.
Please inform the customer of conversation # 1185511 when this conversation has been closed.
Is this going to be fixed at some point given PHP 8.1 released in 2021 and the current version is 8.3. It looks like a small adjustment is needed to the function call to resolve this.
+1 https://wordpress.org/support/topic/deprecation-warning-in-php-8-2/
Literally all that needs to be done to fix this is change line 49 to this:
return \urldecode( \trim( (string) \apply_filters( 'wpseo_canonical', $this->presentation->canonical, $this->presentation ) ) );
Note that the (string) cast that is currently on the trim() call is redundant because trim() can only return a string.
Hi @monkeyArms
Thank you for taking the time to check this issue and for sharing the fix! We truly appreciate your contribution and enthusiasm.
We would love for you to submit your fix as a Pull Request. It will be a great way to ensure your contribution gets properly reviewed and integrated into the project by our development team. You can find more details about contributing here.
I appreciate any help you can provide.
@josevarghese this notice generates an enormous amount of noise if tools like Sentry or similar are in place. We have a composer patch to patch this up in place, but would love it if it could make it upstream.
Hi @aanduque
Thanks for the comment and for taking the time to create a Pull Request! We appreciate your contribution and will look it over as soon as possible. Your efforts to improve the project mean a lot to us.
Please inform the customer of conversation # 1226199 when this conversation has been closed.