Creating default object from empty value in my custom_functions.php

I don’t know how but my theme is showing me this error:

Warning: Creating default object from empty value in /custom_functions.php on line 792

Read More

I found the code in custom_functions.php on line 792 as

    $update_transient->response = array_merge(!empty($update_transient->response) ? $update_transient->response : array(), $et_update_themes->response);

What I need to do, to solve it??

Related posts

Leave a Reply

1 comment

  1. So first explaining how this line works. The question mark is a ternary operator and makes the statement work like this:

    if(array_merge(!empty($update_transient->response)) {
        $update_transient->response = $update_transient->response;
    } else {
        $update_transient->response = array(), $et_update_themes->response);
    }
    

    (The arrows refer to pulling the values from associative arrays or object instances)

    Either way the if statement flows, $update_transient->response is being set to something.
    I would wager that your error is because $update_transient->response is null. You may be seeing this error for the first time because of an upgrade to your PHP version.

    You should try adding an if statement before to check if the value is empty. If it is, then set it to stdClass.

    if (!is_object($update_transient->response)) 
    {
        $update_transient->response = new stdClass;
    }
    

    (stdClass is PHP’s generic empty class)