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

[date_time.php] Functions taking comment arguments have wrong type #1335

Closed
justinbb opened this issue May 1, 2023 · 2 comments
Closed

[date_time.php] Functions taking comment arguments have wrong type #1335

justinbb opened this issue May 1, 2023 · 2 comments
Labels
bug Something isn't working, reproducible severity: critical Critical functionality

Comments

@justinbb
Copy link

justinbb commented May 1, 2023

Describe the bug
Because of a type error in the declaration of qtranxf_dateFromCommentForCurrentLanguage() and qtranxf_timeFromCommentForCurrentLanguage(), display of any article with comments crashes.

Debug info
PHP 7 error message: PHP Fatal error: Uncaught TypeError: Argument 5 passed to qtranxf_timeFromCommentForCurrentLanguage() must be of the type string or null, object given, called in /public_html/wp-includes/class-wp-hook.php on line 303 and defined in /public_html/wp-content/plugins/qtranslate-xt/src/date_time.php:433

PHP 8 error message: PHP Fatal error: Uncaught TypeError: qtranxf_timeFromCommentForCurrentLanguage(): Argument #5 ($comment) must be of type ?string, WP_Comment given, called in /public_html/wp-includes/class-wp-hook.php on line 303 and defined in /public_html/wp-content/plugins/qtranslate-xt/src/date_time.php:433

Additional context
New problem in qtranslate-xt 3.15.0. The argument has always been a WP_Comment, but explicit typing was not previously present.

@justinbb justinbb added the maybe bug Potential bug, to be investigated label May 1, 2023
@herrvigg herrvigg added bug Something isn't working, reproducible severity: major Major functionality severity: critical Critical functionality and removed maybe bug Potential bug, to be investigated severity: major Major functionality labels May 1, 2023
herrvigg added a commit that referenced this issue May 1, 2023
The comment type is not `string` but `WP_Comment`.

Remove default arguments, all must be given in the filter callback.
Clean up obsolete code using global comment variable for older WP.

Fix type signatures in qtranxf_format_* to allow `int` timestamps
when format is 'U'. Add more checks in case `mysql2date` fails.
@herrvigg
Copy link
Collaborator

herrvigg commented May 1, 2023

Good you also caught this. The comment was also wrong for the equivalent date function. These are now fixed in the master branch.

I found many other problems, not only due to the new PHP type signatures but also with the legacy callbacks using wrong parameters. More fixes to come.

herrvigg added a commit that referenced this issue May 1, 2023
No functional impact as this is not passed by the filter.
That function should not be used directly.
herrvigg added a commit that referenced this issue May 1, 2023
@herrvigg
Copy link
Collaborator

herrvigg commented May 1, 2023

Fix released in 3.15.1.

@herrvigg herrvigg closed this as completed May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working, reproducible severity: critical Critical functionality
Projects
None yet
Development

No branches or pull requests

2 participants