I get responses like the following while using Rest APIs:
Notice: Object of class DateTime could not be converted to int in abc.php on line 156
{"success":false,"message":"Something somthing."}
What I want to do is have these warnings redirected to a file but spit out valid response. Something like this:
In debug.log:
Notice: Object of class DateTime could not be converted to int in abc.php on line 156
Actual Response (without the HTML part): {"success":false,"message":"Something somthing."}
I had set the flags as follows: Try 1:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', false);
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
Second try is like this:
ini_set('log_errors','On');
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
None work. Any suggestions ? BTW, I have checked Wordpress and PHP forums and also stackoverflow forums. None of them talk of this scenario (or I have not come across).
You need to first turn off all errors, which can be done using:
error_reporting(0);
Then enable error logging and provide path to log file:
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
Put this at the top of your php file.
Your server did not allow to modify your ini settings.
So if you want to hide add error and notices you can add error_reporting(0); on config page.
// Turn off all error reporting
error_reporting(0);
Other options are available -
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL & ~E_NOTICE);
// For PHP < 5.3 use: E_ALL ^ E_NOTICE
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);