8

My first time posting, I'm hoping someone could help me with this error that has appeared on my website as of Wednesday, I'm not sure how to correct it since I've never touched the .php file.

If I could get some help, I would be really appreciative of it.

The website with error, located at the top of the page.

The error is:

Warning: Creating default object from empty value in whitelight/functions/admin-hooks.php on line 160

Here is the code from lines 150 -170

2
  • Looks like $query_context is an empty variable, and when you have $query_context->context = array();, it triggers that error because the interpreter has to assume that $query_context is an object even though it was not defined as such. Commented Jun 21, 2013 at 23:46
  • 1
    @Cassie: Clicking on your pastebin link tells me that "This paste has been removed!" Could you include the code directly into the question please? Otherwise the question is no longer helpful to other readers with a similar problem. Commented Nov 2, 2014 at 7:53

5 Answers 5

6

This probably means that your host has upgraded the server to php 5.4.x. Please reference this page on how to solve the issue: PHP 5.4: disable warning "Creating default object from empty value"

In summary, You either need have your own error handler or if this is the only place that it occurs then you just need to make it a stdClass before making it an array like so:

} // End IF Statement

if ( !is_object( $query_context ) ) {
  $query_context = new stdClass(); 
}         

$query_context->context = array();

It is also possible that upgrading wordpress and its plugins would solve the problem. I don't know much about that area though...

Sign up to request clarification or add additional context in comments.

Comments

2

The following 2 lines should be added to admin-hooks.php just before the if statement on line 160:

$query_context = new stdClass();
$query_context->context = array();

1 Comment

$query_context = new stdClass(); is the core of the solution :)
0

Insert this at the beginning of whitelight/functions/admin-hooks.php to disable warnings:

error_reporting(E_ERROR);

1 Comment

This does not solve the problem, that line only hides it.
0

This is not really a fix but it should stop the error. Add it to your active themes functions.php /* Stop errors if any /error_reporting(E_ERROR | E_PARSE);/ End stop Errors */

Comments

0

We have PHP v5.4.24 and users are seeing the same error when not logged-in on Wordpress v4.3.1 with Wootique theme v1.6.11. So i added this temp patch until a fix is available.

Added code below to suppress the error. Insert before 'if' statement in admin-hooks.php:

/* suppress error with this */
ini_set('display_errors', 0);

$query_context = new stdClass();    
$query_context->context = array();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.