Skip to content

refactor: Warning: Attempt to read property "ID" on int#299

Open
apermo wants to merge 1 commit intorankmath:masterfrom
apermo:patch-298
Open

refactor: Warning: Attempt to read property "ID" on int#299
apermo wants to merge 1 commit intorankmath:masterfrom
apermo:patch-298

Conversation

@apermo
Copy link
Copy Markdown

@apermo apermo commented Feb 28, 2025

This fixes #298

Moved the definition of $image into if ( is_object( $post ) ) {...} this prevents my reported error Warning: Attempt to read property "ID" on int for $image = Helper::get_thumbnail_with_fallback( $post->ID, 'full' );

The error happened in case global $post was not an object, which most likely will be an integer with value 0 another option would have been to use get_the_ID() since this adds checks by design as well, but since we already have a condition here, I kept the general structure of the function.

@apermo
Copy link
Copy Markdown
Author

apermo commented Mar 6, 2025

@rank-math can you review this please? Thank you :)

@pratikrm
Copy link
Copy Markdown
Collaborator

pratikrm commented Mar 6, 2025

Hi @apermo

Thank you for submitting the issue and the Pull Request. Although we couldn't reproduce this issue on our setup, it makes sense to add a condition to check the WP_Post instance before using the $post object values.

We have logged this as a bug and will include it in the upcoming update.

@apermo
Copy link
Copy Markdown
Author

apermo commented Mar 6, 2025

@pratikrm Thank you, i could neither find the exact conditions how this occured. I assume it's some strange side effect, but adding that condition will definetely fix that error and make Rank Math more robust.

Looking forward to the update.

@apermo
Copy link
Copy Markdown
Author

apermo commented Apr 15, 2025

Any update on this issue?

@pratikrm
Copy link
Copy Markdown
Collaborator

Hi @apermo

We have already fixed this issue in v1.0.240. Could you please update the plugin to the latest version and check if the site still shows the PHP warning?

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 this pull request may close these issues.

Warning: Attempt to read property "ID" on int - RankMath\Frontend\Frontend::rss_replace_vars at line 279

2 participants