• I’m getting an error message “Trying to get property ‘ID’ of non-object” for plugins/insert-php-code-snippet/xyz-functions.php on line 76.

    Please tell me why this error and how to fix it?

    WordPress 6.1.1
    PHP 7.4 (ea-php74)

Viewing 2 replies - 1 through 2 (of 2 total)
  • Would you please check whether there exist a draft page named Snippet Preview.If not please deactivate and activate the plugin and check again.

    Hello,
    I get the exact same error on the main page XYZ PHP Code in WP Admin, above the section with snippets. I have 4 snippets and get 4 Warnings (related?):
    Warning: Attempt to read property “ID” on null in D:\xampp\htdocs\\wp-content\plugins\insert-php-code-snippet\xyz-functions.php on line 76.

    In my case it is related to testing my site in a staging environment to test for PHP 8 fitness.
    So, without any changes to the site, the plugin works fine in PHP 7.4 and throws this warning in PHP 8.
    No drafts exist.

    It looks like it has to do with the increased strictness of PHP 8 concerning variables and identifiers.
    Something like $post or ID not having a value yet?

    I had a few issues with other plugins that I could solve myself, all related to PHP 8 being less forgiving than PHP 7.
    I’m not a programmer and don’t “speak” PHP.
    I added an @ in front of $ (so: @$post) on line 76 and the warnings were gone. But I don’t know if that is a good idea:-).

    Regards, Han

    • This reply was modified 2 years, 1 month ago by hanvroon.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Error message “Trying to get property ‘ID’ of non-object”’ is closed to new replies.