Dima Iva
asked on
Can't get rid of deprecated warnings in PHP error log
I run a journal in XAMP on Windows Server 2016. My c:\xampp\php\logs\php_error_log has thousands of deprecated message every day. It looks like this:
PHP Deprecated: Non-static method PKPApplication::getRequest() should not be called statically in C:\xampp\htdocs\journal\plugins\generic\customHeader\CustomHeaderPlugin.inc.php on line 128
In c:\xampp\php\php.ini I have this line:
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
I tried experimenting with this line, but nothing works. Should I edit something else in php.ini? Or is it possible that php_error_log receives instructions from another .ini file somewhere else?
PHP Deprecated: Non-static method PKPApplication::getRequest() should not be called statically in C:\xampp\htdocs\journal\plugins\generic\customHeader\CustomHeaderPlugin.inc.php on line 128
In c:\xampp\php\php.ini I have this line:
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
I tried experimenting with this line, but nothing works. Should I edit something else in php.ini? Or is it possible that php_error_log receives instructions from another .ini file somewhere else?
Run phpinfo() and see where the 'php.ini' file that is being used is located. I think it's in the Apache file for PHP.
ASKER
I have this in phpinfo():
Configuration File (php.ini) Path | C:\Windows |
Loaded Configuration File | C:\xampp\php\php.ini |
Scan this dir for additional .ini files | (none) |
Additional .ini files parsed | (none) |
In my copy of WAMP, I have this:
Apache normally loads it own copy of 'php.ini'. The copy in C:\xampp\php\php.ini is normally used just for the command line operation of PHP.
Also... 'php.ini' is normally only loaded when the web server is rebooted. That's the only time you see changes.
Configuration File (php.ini) Path | C:\Windows |
Loaded Configuration File | C:\wamp64\bin\apache\apache2.4.27\bin\php.ini |
Also... 'php.ini' is normally only loaded when the web server is rebooted. That's the only time you see changes.
Tip: Best be clear about what "Deprecated" means.
1) The feature you're using will eventually disappear from PHP support.
2) At such time as when #1 occurs, the "Deprecated" error will be prompted to a "Fatal" error + your code will simply start dying.
3) The fix is... Fix your code...
4) If you suppress this error, which you can easily do... then all will be well... till... it's not...
Suppressing these errors, rather than fixing them, means next indication you'll have of the problem is when your code starts crashing/dying.
1) The feature you're using will eventually disappear from PHP support.
2) At such time as when #1 occurs, the "Deprecated" error will be prompted to a "Fatal" error + your code will simply start dying.
3) The fix is... Fix your code...
4) If you suppress this error, which you can easily do... then all will be well... till... it's not...
Suppressing these errors, rather than fixing them, means next indication you'll have of the problem is when your code starts crashing/dying.
To suppress these errors, simply remove ~E_DEPRECATED from your error reporting bits.
ASKER
I see, Dave, that WAMP has
My XAMPP, however, doesn't have a C:\xampp\bin directory. It has C:\xampp\apache, xampp\php, etc. xampp\apache has no *.ini files in it. I searched all *.ini files in all C:\xampp directories for the word "deprecated" and only found
C:\xampp\php\php.ini, which right now has:
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING & ~E_DEPRECATED
and C:\xampp\htdocs\journal\lib\pkp\lib\vendor\smarty\smarty\error_reporting.ini, which has:
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
Every time I edit php.ini, I restart the Apache2.4 service, but it almost looks like the logging configuration is located in a non *.ini file somewhere? Could you think of something else?
P.S. I get David's message that perhaps the script has to be fixed, and I will ask script authors about ways to fix it, but I am still interested in figuring out the mystery of the error logging.
C:\wamp64\bin\apache\apache2.4.27\bin\php.ini |
My XAMPP, however, doesn't have a C:\xampp\bin directory. It has C:\xampp\apache, xampp\php, etc. xampp\apache has no *.ini files in it. I searched all *.ini files in all C:\xampp directories for the word "deprecated" and only found
C:\xampp\php\php.ini, which right now has:
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING & ~E_DEPRECATED
and C:\xampp\htdocs\journal\lib\pkp\lib\vendor\smarty\smarty\error_reporting.ini, which has:
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
Every time I edit php.ini, I restart the Apache2.4 service, but it almost looks like the logging configuration is located in a non *.ini file somewhere? Could you think of something else?
P.S. I get David's message that perhaps the script has to be fixed, and I will ask script authors about ways to fix it, but I am still interested in figuring out the mystery of the error logging.
What version of WAMP do you have?
My mistake, my version of XAMP 1.8.2 (not WAMP) has the same configuration that yours does.
ASKER
My XAMPP is 3.2.2 and its structure looks like this in Windows Explorer:
The app I use - OJS from PKP - is sitting in htdocs\journal, but php.ini is in php.
The app I use - OJS from PKP - is sitting in htdocs\journal, but php.ini is in php.
Try...
# Suppress deprecation errors
error_reporting = E_NOTICE & E_STRICT & WHATEVER-ELSE-MIGHT-BE-INTERESTING
# Suppress all error reporting
error_reporting(0);
ASKER
David, I tried both lines and restarted the Apache2.4 service each time.
error_reporting(0); -> works great, no new error messages at all!
error_reporting = E_NOTICE & E_STRICT -> deprecated messages keep appearing.
So, changes in the same C:\xampp\php\php.ini file work to completely repress all error messages, but not some.
error_reporting(0); -> works great, no new error messages at all!
error_reporting = E_NOTICE & E_STRICT -> deprecated messages keep appearing.
So, changes in the same C:\xampp\php\php.ini file work to completely repress all error messages, but not some.
Don't suppress errors / warnings. They are there for a reason. You might not want to see this particular warning but suppressing them means you will potentially miss other errors / warnings you do want to see.
The right solution is - fix the problem.
Either update the the plugin to its latest version
OR
Find a plugin that has been written correctly
OR
Fix the problem.
This problem is not particularly difficult to fix - add static to function definition
The right solution is - fix the problem.
Either update the the plugin to its latest version
OR
Find a plugin that has been written correctly
OR
Fix the problem.
This problem is not particularly difficult to fix - add static to function definition
public static function getRequest(...)
ASKER
Thank you, Julian. I agree with you and with David saying that I don't have to hide the error messages. I am just curious why on Earth I cannot hide a certain type (like "deprecated"), although it should be straightforward.
But I am going to unhide the error messages and try to fix the code. I am just not sure where I need to insert
public static function getRequest(...)
because this function (and the line 128) look like this:
119: /**
120: * Add custom footer to the page
121: *
122: * @param $hookName string
123: * @param $params array
124: */
125: function insertFooter($hookName, $params) {
126: $templateMgr =& $params[0];
127: $output =& $params[2];
128: $request = Application::getRequest();
129: $context = $request->getContext();
130:
131: $output .= $this->getSetting($context?$context->getId():CONTEXT_ID_NONE, 'footerContent');
132:
133: return false;
134: }
But I am going to unhide the error messages and try to fix the code. I am just not sure where I need to insert
public static function getRequest(...)
because this function (and the line 128) look like this:
119: /**
120: * Add custom footer to the page
121: *
122: * @param $hookName string
123: * @param $params array
124: */
125: function insertFooter($hookName, $params) {
126: $templateMgr =& $params[0];
127: $output =& $params[2];
128: $request = Application::getRequest();
129: $context = $request->getContext();
130:
131: $output .= $this->getSetting($context?$context->getId():CONTEXT_ID_NONE, 'footerContent');
132:
133: return false;
134: }
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
I would use Wampserver it is much easier to set and use https://wampserver.aviatechno.net/
and it come with Xdebug preinstalled which is great.
If your OS is Windows sometimes a duplicated php.ini could be found in Windows directory.
(this may happened if you have previously installed PHP manually.
The PHP application may have error display settings in config file or directly on the PHP page.
In any case you may want to fix the problem before it become an error.
I would use Wampserver it is much easier to set and use https://wampserver.aviatechno.net/
and it come with Xdebug preinstalled which is great.
If your OS is Windows sometimes a duplicated php.ini could be found in Windows directory.
(this may happened if you have previously installed PHP manually.
The PHP application may have error display settings in config file or directly on the PHP page.
In any case you may want to fix the problem before it become an error.
ASKER
Turned out that the function was declared in a different directory: C:\htdocs\journal\lib\pkp\classes\core\PKPApplication.inc.php
Added "static" to it and voila - mission accomplished. This particular deprecated error is gone and I am allowing error messages, w/o being overloaded by them. Just as Julian and David suggested.
Added "static" to it and voila - mission accomplished. This particular deprecated error is gone and I am allowing error messages, w/o being overloaded by them. Just as Julian and David suggested.
Glad you got this working!
Better to fix the problem, rather than suppress the error.
Better to fix the problem, rather than suppress the error.