Turn off notices in cakePHP - php

I am new with cakePHP. I facing issue with notice on live server. I want to suppress or turn off these notices. I have tried adding,
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
in the index.php file in main folder. Also added same in bootstrap.php file but no luck. Can anybody suggest me how I can do this.

You can disable the debug feature by turning debug to 0 in the app\Config\core.php file
Configure::write('debug', 0);
If still you get the same issue so please check your live server Php version and also check the same on development server, I think there is php version compatibility issue so please see
link http://bakery.cakephp.org/articles/markstory/2013/07/05/cakephp_2_3_7_2_4_0-beta_released
Hope it should work for you.

In the core.php file in /app/config, find this line and edit the level of errors you want to show:
Configure::write('Error', array(
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));
You may now add or remove the error levels as given on this page: http://php.net/manual/en/function.error-reporting.php

Open config/core.php
0: No error messages, errors, or warnings shown. Flash messages redirect.
*
Development Mode:
1: Errors and warnings shown, model caches refreshed, flash messages halted.
2: As in 1, but also with full debug messages and SQL output.
seach this
Configure::write('debug', 0);

You are getting warnings and notice just because your DEBUG is TRUE. to solve this probem.
Go to config/app.php and just change true to false as done below..
Find this line
'debug' => filter_var(env('DEBUG', true), FILTER_VALIDATE_BOOLEAN),
And change above line to
'debug' => filter_var(env('DEBUG', false), FILTER_VALIDATE_BOOLEAN),

Try this in config/app.php file:
'Error' => [
'errorLevel' => E_ALL & ~E_USER_DEPRECATED & ~E_NOTICE & ~E_WARNING,
......
......
],

Related

Why is the wordpress fatal error not being displayed?

Our site was migrated due to issues on our server providers end. It caused many errors and I fixed most of them. Now, for some pages, it just says there is an error. It display notices and a depreciated warning but I know this will not cause the entire page to stop working. Why is the fatal error not being displayed?
This is what I have tried.
define( 'WP_DEBUG_LOG', 'error.log' );
ini_set('display_errors','on');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', true);
error_reporting(E_ALL);
Normally it would show a fatal error. I don't know why it isn't showing me the important error.
Please help!
First ensure that there is no place in your code where you set error_reporting to 0
e.g.
error_reporting(0);
as this will totally hide all error warnings and notices.
In php script, this three line of code will just turn it on
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
You should see the same messages in the PHP error log.
Other things that you will need to check
1.) PHP.INI Files or your Apache configurations
You can move to your php.ini files and ensure that the following parameters below are commented out and set on.
By commented out, I mean removing a semicolon**(;)** at back of it
Eg.
uncomented = ;display_errors=On
commented = display_errors=On // semicolon removed
display_errors=On
display_startup_errors=On
track_errors = On
html_errors=On
shutdown and restart apache for it to take effect.
2.) .HTACCESS Files
You can also check .htaccess files to see if any of these warning parameter flags are set to 0 which means off and set them to 1 which means On.
Remember to turn off all these error warnings in production.

Suppress PHP warnings and notices in WordPress pages

When I try to load WordPress, I get a lot of Use of undefined constant ‘view’ - assumed '‘view’' type of warnings and notices in the browser. This causes the pages to fill up with these messages before it renders the actual page content expected.
I tried changing error_reporting = E_ALL to error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING but the warnings and notices still show up.
After doing php --ini I located both the 7.0 and 7.1 ini files and updated the value in both and restarted both FPM services on my vagrant.
/etc/php/7.0/fpm/php.ini
/etc/php/7.1/fpm/php.ini
Why are these still showing up?
You can combine WordPress build-in constants and PHP's ini settings.
Place these lines in your wp-config.php
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);
This way all notices, warnings and errors will not be shown on the front-end of your website, but errors are still accesable by a log file.
Looks like you copied the code from some source and pasted in your file, the inverted quote ` is used instead of ', simply change the single quote and it will be fixed.
change ‘view’ to 'view' and so on.
To show errors and hide notices (and as was asked, warnings) there is a hacky way in wp-config.php:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', true );
plus this at the end of the file after wp-settings.php is loaded:
/*hide notices and warnings*/
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING );
I'm saying hacky only because it's after the line saying /* That's all, stop editing! Happy publishing. */ :)

Yii2 not catching fatal errors when error_reporting is set

When setting Yii2 to production mode in index.php -
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod')
I have a logger, which correctly logs errors while in production mode, and prints out an appropriate error message on user page, but also show these error messages on notices (killing pages unnecessarily).
So, I set error_reporting in index.php -
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
But this prevents Yii2 from catching errors at all, so that they don't get logged, and renders a blank page in the event of any error allowed by error_reporting. It prevents notices from killing the page, but logging quits working when I use error_reporting()
Is there a Yii2 appropriate way of doing this? Has anyone had this issue before? Thanks for all attempted solutions.
The error log configuration -
$log['targets'][] = [
'class' => 'understeam\slack\LogTarget',
'exportInterval' => 1,
'levels' => ['error', 'warning'],
'except' => [
'yii\i18n*',
'yii\web\HttpException:404',
'yii\web\HttpException:403',
'yii\web\ForbiddenHttpException',
'yii\web\NotAcceptableHttpException',
'yii\base\InvalidRouteException'
],
];
The above is using the vendor package "understeam/yii2-slack": "~0.3"
It was interesting case for me, and I had similar problem, and I think there is no way to solve this with internal Yii2 ErrorHandler. So I decided to create a package with extended ErrorHandler that I hope can solve your issue.
Install it:
php composer.phar require cronfy/yii2-web-errorhandler
Set error reporting to report all errors:
error_reporting(E_ALL);
Configure error handler component in yii config:
'components' => [
'errorHandler' => [
'class' => 'cronfy\yii\web\ErrorHandler',
'typesToExceptions' => YII_DEBUG ? E_ALL : false,
'typesToLog' => E_ALL,
],
// ... other components
],
With this configuration:
In DEBUG mode all errors will be logged AND converted to exceptions.
In PRODUCTION mode all errors will be logged too, but will NOT provide exceptions that would break page.

CakePHP 1.3 PHP Strict Warnings

I know there's a LOT of stuff written here about this but we're running a CakePHP 1.3 on the newest PHP version on our Debian server. Right now there's multiple people using the system and I just had to delete a 17GB error.log from the server. It keeps pushing PHP Strict Standards error messages to it even though I've supressed the messages from the CakePHP /cake/bootstrap.php by adding the ~E_STRICT and I've thought about adding this..
Configure::write('Error', array(
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED & ~E_STRICT,
'trace' => true
));
.. to the /app/core.php but I'm afraid to go do it on a live operation.
Why cannot I suppress these messages from the bootstrap.php or is the core.php the only way even though the Configure::write('Error'), array()); is commented out in there?
Configure::write('log', E_WARNING);
This would log only warning and fatal errors. If you want to disable error logging, this should work:
Configure::write('log', false);

How to eliminate php5 Strict standards errors?

After upgrading my PHP to 5.4.3 (WAMP server 2.2), my web app made in CakePHP 1.3, is showing the following errors in my index:
Strict standards: Redefining already defined constructor for class
Object in C:...\cake\cake\libs\object.php on line 63
Strict standards: Non-static method Configure::getInstance() should
not be called statically in C:...\cake\cake\bootstrap.php on line 49
I've found that some people solve this problem by setting the error_reporting in php.ini to E_ALL & ~E_STRICT.
I did that in both php.ini files (C:\wamp\bin\php\php5.4.3 and C:\wamp\bin\apache\apache2.4.2\bin) present on my computer but it didn't solve the problem.
I also tried to put php_value error_reporting 6143 in C:...\cake.htaccess but without success.
Does anybody know how can I solve this? I can't upgrade my CakePHP because of firebird.
One of the changes in php 5.4 is that E_STRICT is now part of E_ALL
So, in your /cake/bootstrap.php you could remove the E_STRICT from your error reporting:
error_reporting(E_ALL ^ E_STRICT);
and be compatible again with before 5.4 versions.
Instead of modifying the cake core files, which sucks if you want to update your cake version, go into your Config/core.php file and look for the error handler configuration:
Configure::write('Error', array(
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));
and replace 'level' with this:
...
'level' => E_ALL & ~E_STRICT & ~E_DEPRECATED,
...
Please replace
error_reporting = E_ALL
in your php.ini, with
error_reporting = E_ALL & ~E_STRICT
For me
error_reporting(E_ALL ^ E_STRICT);
which is shown in the accepted answer to this question did not work and gave an Infinite loop detected in JError error for my Joomla website.
You are using newer php version. in php 5.4, E_STRICT is part of E_ALL
in cake 1.3, open file /cake/bootstrap.php and change the error_reporting like this
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
If you're fighting with PHP Strict warnings in cake console output, take a look into your app/config/core.php.
In CakePhp 1.3 error_reporting(...) is overwritten by the 'log' option, so ensure you exclude E_STRICT here:
/**
* CakePHP Log Level:
*
* In case of Production Mode CakePHP gives you the possibility to continue logging errors.
*
* The following parameters can be used:
* Boolean: Set true/false to activate/deactivate logging
* Configure::write('log', true);
*
* Integer: Use built-in PHP constants to set the error level (see error_reporting)
* Configure::write('log', E_ERROR | E_WARNING);
* Configure::write('log', E_ALL ^ E_NOTICE);
*/
Configure::write('log', E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
Make sure you've updated the correct php.ini file - if you create a php file in your root directory with the following code
<?php
phpinfo();
?>
and load it in your web browser it will tell you which ini file is being used, in case you missed one.
It's also possible that an htaccess file is setting that value via the php_flag error_reporting value, which can also be set per directory.
File bootstrap.php from folder (root)cake
if (!defined('E_ALL')) {
define('E_ALL', 8192);
}
File debugger.php from folder (root)cake\libs
error_reporting(E_ALL ^ ~E_STRICT ^ ~E_DEPRECATED);

Categories