Suppress warnings in mediawiki - php

Is there any way to suppress deprication warnings in mediawiki?
For e.g. I am getting this message at the top of some of the pages on my personal wiki site.
Deprecated: Use of MWNamespace::getSubject was deprecated in MediaWiki 1.34. [Called from Scribunto_LuaSiteLibrary::register in /var/www/html/w/extensions/Scribunto/includes/engines/LuaCommon/SiteLibrary.php at line 58] in /var/www/html/w/includes/debug/MWDebug.php on line 375
You can see an example here...
http://training.shantanuoak.com:8080/wiki/%E0%A4%AE%E0%A4%BE%E0%A4%B0%E0%A5%8D%E0%A4%95_%E0%A4%AC%E0%A5%87%E0%A4%A8%E0%A5%8D%E0%A4%B8%E0%A4%A8
I am not sure if this is php issue or mediawiki problem.

At the bottom of LocalSettings.php:
$wgShowDebug = false;
$wgDevelopmentWarnings = false;
If you want to keep debug messages around, just not the deprecation ones:
$wgDeprecationReleaseLimit = '1.0';
Also, upgrading MediaWiki and extensions helps with problems sometimes😃

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

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.

pyrocms theme error drivers/Session_cookie.php

I'm new to PyroCMS and I'm currently working on a news website which requires the blog functionality. In order not to have my urls displaying "blog" I duplicated the blog module and renamed it "posts" which worked fine.
But now when I view a post I get the following error at the top of the page:
"A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/newerawe/public_html/addons/default/themes/era/theme.php:1)
Filename: drivers/Session_cookie.php
Line Number: 701"
Because you didn't mention the most crucial information of all, what php and pyro version you are using .. i have to assume you are using PHP 5.4 the PyroCMS 2.2.
There is something sent before a header, PyroCMS had some problems with this kind of stuff, because PHP has gotten a bit more strict and is throwing several warnings if for example you are trying to create a variable out of thin air:
This will issues an warning saying that $text hasn't been defined, and that happens before the headers, which causes the problem.
// Warning: "Creating default object from empty value" errors
$text->string = 'My text is fine';
You nead you need to either find and fix the problems, which is a long shot:
$text = new stdClass();
$text->string = 'My text is fine';
or try exclude E_WARNING from error_reporting, and you should be fine.
error_reporting(E_ERROR | E_PARSE | E_NOTICE);
Hope that it helps!

Error: Warning: Creating default object from empty value

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

PHP 5.4: disable warning "Creating default object from empty value"

I want to migrate code from PHP 5.2 to 5.4. This worked fine so far except that all the code I use makes extensive use of just using an object with a member without any initialisation, like:
$MyObject->MyMember = "Hello";
which results in the warning: "Creating default object from empty value"
I know that the solution would be to use:
$MyObject = new stdClass();
$MyObject->MyMember = "Hello";
but it would be A LOT OF WORK to change this in all my code, because I use this many times in different projects. I know, it's not good style, but unfortunately I'm not able to spend the next weeks adding this to all of my code.
I know I could set the php error_reporting to not reporting warnings, but I want to be able to still get other warnings and notices. This warning doesn't seem to be effected by enable or disable E_STRICT at all. So is there a way to just disable this warning?!
Technically you could do this by installing your own error handler for warnings. From inside the handler check the string error message; if it's the one you want to suppress then return true, otherwise return false to let the default error handler do its thing.
However I would still recommend doing the right thing and manually fixing your code wherever this misuse does appear because, if nothing else, it gets you into the correct habit. Unless this is paid work (in which case there usually are concerns that override purity of implementation), consider this as a lesson and do the right thing.
I know I could set the php error_reporting to not reporting warnings, but I want to be able to still get other warnings and notices.
Don't disable the error reporting, leave it at an appropriate level, but disable the display_errors directive:
ini_set('display_errors', 0);
There's no reason to print notices to the screen in production.
Then as Jon said, use a custom error handler if you aren't already, example:
function my_error_handler($error_level, $error_message)
{
// write error message to log file
}
set_error_handler('my_error_handler');
You can pass in the error reporting level to the second param of set_error_handler. This way you can take your time and do the right thing, which is fix the code to stop generating notices.
If you're moving a lot of sites over to 5.4, you can probably have your server admin turn off display_errors in php.ini until you have enough time to fix everything. Better yet, stage everything and fix it before upgrading, but that may not be an option.
you really could use an IDE for php and try to do this:
Search for $MyObject->MyMember = "Hello";
Look for the results and if it brings the right things, try to replace that with:
$MyObject = new stdClass();
$MyObject->MyMember = "Hello";
So maybe the IDE would do the long work for you...
I had the same problem i handle it like bellow in production environment
\error_reporting(\E_ERROR);
I have to say that my application doesn't need/generate errors, it's on a very controlled environment so doing this wouldn't hurt much, but if your application is an error prone one you should have you own error handler and with a proper regex and preg_match ignore the “Creating default object from empty value” warning and log/prompt others at your discretion.

Categories