简体   繁体   中英

PHP Notice: Trying to get property of non-object in /wp-includes/query.php on line 4654

My error log is filled with this: PHP Notice: Trying to get property of non-object in /home/.../wp-includes/query.php on line 4654

Line 4654 is as follows: return in_array( $post_obj->post_type, (array) $post_types );

How can I diagnose what exactly is causing this? I assume some code elsewhere is accessing query.php and causes this error but I don't see any hint other than the one above.

Please do not just say "ignore it, it's nothing", I do my best to keep my site error-free so I'd really like to find out what this is and fix it.

Thanks in advance

There is a difference between accessing values from arrays and from objects.

To access a value from an object, you do it like so:

$object->valueKey

This will return the value of the that key within that object.

To access a value from an array, you need to do it like ths:

$array['arrayKey']

This will return the value of that key within the array.

You cannot interchangeably use these methods. This error means that your variable IS NOT an object. Meaning it is either null, or an array, or another datatype.

Try doing var_dump($variable) ; it will tell you what is actually inside the variable and tell you if it is an object or an array or whatever else the case may be.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM