refactor: Warning: Attempt to read property "ID" on int#299
refactor: Warning: Attempt to read property "ID" on int#299apermo wants to merge 1 commit intorankmath:masterfrom
Conversation
|
@rank-math can you review this please? Thank you :) |
|
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 We have logged this as a bug and will include it in the upcoming update. |
|
@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. |
|
Any update on this issue? |
|
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? |
This fixes #298
Moved the definition of $image into
if ( is_object( $post ) ) {...}this prevents my reported errorWarning: Attempt to read property "ID" on intfor$image = Helper::get_thumbnail_with_fallback( $post->ID, 'full' );The error happened in case
global $postwas not an object, which most likely will be an integer with value0another option would have been to useget_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.