Error: Warning: Creating default object from empty value - php

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

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...

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();

Insert this at the beginning of whitelight/functions/admin-hooks.php to disable warnings:
error_reporting(E_ERROR);

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 */

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();

Related

Code that throw Deprecated warnings works correctly, but updated code does not work?

I am using the following code as part of a function on my site. This is a snippet - of course the function contains a lot more information, however that is not relevant to my current issue:
$get_product_id = wc_get_product(get_the_ID());
$get_title = $get_product_id->get_name();
$get_cat = $get_product_id->get_categories(); // FAILING
$get_tag = $get_product_id->get_tags(); // FAILING
$output = '';
As things stand, all 5 lines of code work correctly and allow me to display on the front end, all the correct information I require, however in my debug.php file, I am getting the following errors:
PHP Deprecated: WC_Product::get_categories is deprecated since version 3.0! Use wc_get_product_category_list instead.
and
PHP Deprecated: WC_Product::get_tags is deprecated since version 3.0! Use wc_get_product_tag_list instead.
I understand this is because I am using outdated PHP, but the errors leave me with two questions:
Is it bad to ignore debug errors if the code appears to work correctly? I noticed some of the third-party plugins my site uses also return the odd debug error (some of the plugin come from very reputable sources too)!
Upon attempting to use the new (correct) code, I was unable to get any post values and kept getting empty an empty return. What do I actually need to change to get my code working correctly and without it giving me debug errors?
Is it bad to ignore debug errors? I'm not going to answer good or bad, but debug errors generally mean that something larger might be broken or not behaving correctly. Further, your debug warnings are deprecation warnings, which are a specific case of warning to be aware of. Some/many/most libraries have a deprecation schedule where in version X they'll deprecate a feature and in version X+1 they'll complete remove it. Whether WooCommerce will do this I can't say, but you should assume that it could happen at any given moment and take action.
How to fix. If you look at the source code for the get_tags (line 386 as of today) you'll see that they are actually using the new function already, so you should be able to swap it in directly.
public function get_tags( $sep = ', ', $before = '', $after = '' ) {
wc_deprecated_function( 'WC_Product::get_tags', '3.0', 'wc_get_product_tag_list' );
return wc_get_product_tag_list( $this->get_id(), $sep, $before, $after );
}
So instead of:
$get_tag = $get_product_id->get_tags(); // FAILING
You should be able to just use:
$get_tag = wc_get_product_tag_list(get_the_ID());

Wordpress - The7 Template - On every page I have 4 Warnings and do not know how to disable it in menu or php site/content

I have a problem with my Wordpress site, more specifically, The7 template. On every page, including the main page at the bottom of page below footer I have 4 Warnings which are the same:
“Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘wp_filter_content_tags’ not found or invalid function name in on line”
I do not know how to solve it/turn it off. Could you tell me which PHP page or what exactly cause this problem to appear? It’s really annoying. Due to the fact that it is in the main body and not in any div/b/p/etc. tag I cannot hide it with CSS just for a while.
Kind regards
Peter
Hiding error reporting on prod
On prod you want to avoid showing errors, due to security and user experience reasons. To achieve this, in PHP you can run
error_reporting(0);
or, even better, in php.ini, you can have this line
error_reporting = off
What the error means
The error tells you that a function is to be called by name, but it does not exist. wp_filter_content_tags does not exist in your context.
Solution to the error
Even though you have hidden error reporting on prod, you still need to show errors on dev and that function might do something very useful. From the doc you can see that it's located in wp-includes/media.php. So, if you do not need to call this function, then search for its calls and remove them. If you need this function, then require or include it into your files. If, for some reason you cannot remove this function (for ex. you do not want to hack a template that might have some versions in the future), but the function/file is not helpful for you, then you can implement a function with the same name.
Thank you very much for answer. I used it to find solution and in my case there is a need to change wp-config.php a little bit. It means to add these specific lines to code:
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false)
In my case it worked and no more errors / warnings showed on every / main pages.
Kind Regards
Peter

Notice: Trying to get property of non-object in ../libraries/src/UCM/UCMType.php on line 169

When I tried to install the Joomla! extension JCH, I came up with the title message above after finished installing.
I asked the developer and he replied that I don't have to worry about the extension as this is a Joomla! issue that it will not affect the way the extension works.
The line 169 of UCMType.php is the following:
$tableNameFromType = $tableFromType->special->prefix . $tableFromType->special->type;
And the specific part of the UCMType.php that includes line 169:
public function getTypeByTable($tableName)
{
$query = $this->db->getQuery(true);
$query->select('ct.*');
$query->from($this->db->quoteName('#__content_types', 'ct'));
// $query->where($this->db->quoteName('ct.type_alias') . ' = ' . (int) $typeAlias);
$this->db->setQuery($query);
$types = $this->db->loadObjectList();
foreach ($types as $type)
{
$tableFromType = json_decode($type->table);
$tableNameFromType = $tableFromType->special->prefix . $tableFromType->special->type;
if ($tableNameFromType === $tableName)
{
return $type;
}
}
return false;
}
You really do not have to give too much attention for this issue, so the third party extension developer was right in this. This is more like a small bug (thus the Notice is there), not a serious Error. Your site will operate without a problem.
As you see in this Notice, in the foreach(){} loop a variable is tried to be defined from another variable which is not an Object, so it is just getting back a NULL value or another TYPE most probably, which does not have an Object property what is expected there.
In this particular case this whole thing happens in a relatively new Joomla core class and interface (UCM and UCMType). In this class they want to define a content type by table and this part of the code has to be modified, improved by core Joomla developers.
What should you do?
1. If you want to help the development of Joomla and yourself a bit then please report this issue here: https://developer.joomla.org/tracker.html , and they will check and repair this most probably.
2. This PHP (error) Notice is usually for developers, so if your site is a live site you should not see this Notice basically. If you see this on live site, that could mean that either your Joomla error reporting is set incorrectly, or your server error reporting default is set incorrectly.
In your Joomla admin at System->Global Configuration->Server->Error reporting has to be set to System Default or to None. Thus these not relevant notices will not appear for users, visitors of your site. Other settings only recommended if your site is not a live site and you develop that further in a staging copy for example.
And please if you have Joomla questions, visit the Joomla Stack Exchange here: https://joomla.stackexchange.com/questions and please ask your questions regarding Joomla there.
I hope the above cleared the issue for you.

error in /modules/mod_feed/helper.php

I am getting a warning after PHP update
Warning: Creating default object from empty value in /modules/mod_feed/helper.php on line 42
I had faced this issue before and at that time I have used $v=new stdclass();. But the issue was not in a Joomla site. Now the same issue with a joomla site. My code link is here
What I should change in this file? Any thoughts?
You also need
$feed->image = new stdclass;
before line 42. This is an E_STRICT level warning. These are designed to alert you to code smells (like auto-creating arrays / objects).

Reset PHP Error before running included script

I am combining two existing scripts to built something new and safe time by using existing code:
php_simple_html_dom to parse some html
the wp-db.php class from wordpress to access the database
These two scripts don't play nicely along. I used xdebug to find out that the main problem was caused in this piece of code in php_simple_html_dom:
if (($error=error_get_last())>null) {
$this->clear();
return false;
}
Because the wordpress template I use fires some E_NOTICE level errors this results in my php_simple_html_dom getting cleared.
The weird thing is, I do not include any template code as I include and instantiate wp-db.php myself like this:
require_once('../wp-config.php');
require_once('../wp-includes/wp-db.php');
$wpdb = new wpdb(DB_USER,DB_PASSWORD,DB_NAME,DB_HOST);
Even when I step through the code completely with xdebug it never hits anything else from wordpress then wp-config.php or wp-db.php.
Edit:
As indicated by horatio, this actually does get called from the
include of wp-settings.php in the end of wp-config.php. I now
understand why my debugger never hit it: netbeans had failed to
download wp-settings.php so it could not debug it.
Nevertheless this is the error returned by error_get_last():
Array
(
[type] => 8
[message] => Undefined index: id
[file] => (real-path-deleted)/wp-content/themes/supermassive/lib/inc/options.php
[line] => 10
)
I think I could solve this problem using one of two different strategies:
1. Stop the unneccessary wordpress code that is causing the errors from running.
Reset the error returned by error_get_last() before php_simple_html_dom is run.
Which of these would be the best and how would I go about to achieve it?

Categories