What does “Trying to get property of non object in..” mean?

The root problem here is assumptions.

For example lets say we have an array here:

$test = [
    'foo' => 'bar'
];

If we run echo $test['foo']; we should see bar, but what if we ran echo $test['bananas'];? There is no bananas entry in that array, so PHP will notice this, throw a warning/notice similar to the one you’re seeing, then fill in the missing value with '' or null.

This also happens with objects, e.g. if we take a classic post object and try to do this: echo $post->odijfnvlkdsfnvlkjdsnvkljdfnv;, we’ll get a warning/notice

The same is true of your code. Most likely, the code calls an API but never checks if it was succesful, and just assumes it was. Or, a variable is misspelt.

You can check for these things with guards such as if ( !empty( ... ) ) {, or by checking return values on WP functions to see if they returned what you expected them to, or if something went wrong.

What could be happen? I have made rollback but the message still appear. Is it dangerous?

Yes and no, there are possible consequences of this, and it depends a lot on what you’re doing and how it could interact. Because you’re assuming the values are good when they aren’t, or using things that don’t exist, PHP will substitute a placeholder value. That value is a false-ish value, and might mess up your logic, or lead to unexpected situations. That could be cryptic errors, or avenues to exploit security.

The biggest issue is when PHP is configured to show these warnings on the frontend, which can break REST XMLRPC and AJAX, as well as anything that changes HTTP headers to do things

The most annoying issue though, is that debugging with a PHP error log becomes almost impossible due to the huge numbers of warnings this would generate. Anything of interest becomes buried under a deluge of notices about object properties and array keys being access that don’t exist.

Leave a Comment