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);
Related
I am working on project # home and using WAMP for development. Currently the php.ini file has the following lines set like this:
error_reporting = E_ALL & ~E_DEPRECATED
display_errors = On
I had hoped in doing so it would prevent deprecation warnings from showing up. However it is not. Is there a way I can adjust error_reporting to ignore deprecated warnings.
Output I am getting currently:
You can use this function :
error_reporting(E_ALL ^ E_DEPRECATED);
http://www.php.net/manual/en/function.error-reporting.php
Or use "#" operator before function name.
#mysql_connect();
In your php.ini file change the following.. (note wamp has 2 different php.ini files so make the changes on both)
from this
error_reporting = E_ALL
to this
error_reporting = E_ALL & ~E_DEPRECATED
I had the same problem. It turned out however, that I edited wrong php.ini file. In my case the correct one was
C:\wamp64\bin\php\php5.6.25\phpForApache.ini
and in this file I have changed this line to:
error_reporting = E_ALL & ~E_DEPRECATED.
It didn't make any difference what I had changed in that "obvious" php.ini file.
Set your error report to
error_reporting (E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
on your php page.
If you want to show all errors except deprecated, then use this setting:
error_reporting = E_ALL ^ E_DEPRECATED
Edit: You could also create a custom error handler to hide only mysql_ deprecation warnings:
set_error_handler(function($errno, $errstr) {
return strpos($errstr, 'mysql_') === 0;
}, E_DEPRECATED);
But please note that mysql_ functions are deprecated. So instead of trying to hide the errors, consider switching to mysqli or PDO.
To hide php errors on WAMP server, Please open php.ini file and find following line of code
error_reporting = E_ALL
and replace it with
error_reporting = E_ALL & ~E_NOTICE
All errors will be hide/disable.
Warning: include(../config.php): failed to open stream: No such file or directory in C:\wamp\www\happyDB\script\logincheck.php on line 3
The funny thing is, is its working fine and the file its saying isn't there is... Any ideas?
Because it's configured to do so in the php.ini file.
PHP 5.3 or later, the default value is E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED. This setting does not show E_NOTICE, E_STRICT and E_DEPRECATED level errors. You may want to show them during development. Prior to PHP 5.3.0, the default value is E_ALL & ~E_NOTICE & ~E_STRICT. In PHP 4 the default value is E_ALL & ~E_NOTICE.
Have a look at the PHP docs to see how to modify the situations in which PHP reports errors.
http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting
I want to enable deprecated errors globally but disable them for a specific piece of third-party code, which I don't have the time to fix.
So, I have this in php.ini:
error_reporting = E_ALL & ~E_NOTICE | E_DEPRECATED
and this right before the line where I want to disable the warnings
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
However, it does not work, I'm still getting the warnings for that particular line. If I disable them globally in php.ini it works. I'm using PHP 5.3.10. Any ideas what might be wrong?
Figured it out. The third party code has custom error handler and apparently it's overriding anything you set with error_reporting(). When I commented out the set_error_handler() line, error_reporting() took effect.
Add the below error reporting line in your php.ini:
error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED);
Then restart your server and check it.
I need to turn off E_STRICT. I have error_reporting = E_ALL & ~E_STRICT in my php.ini but it seems to be ignored. I tried this in my code:
ini_set('error_reporting', E_NOTICE);
Nothing!
Please help.
try this.
error_reporting(E_ALL ^ E_STRICT);
This will report all errors except E_STRICT
If you've got your own error handler (search your code for set_error_handler), then the error_reporting config value will be ignored:
It is important to remember that the standard PHP error handler is completely bypassed for the error types specified by error_types unless the callback function returns FALSE. error_reporting() settings will have no effect and your error handler will be called regardless - however you are still able to read the current value of error_reporting and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the # error-control operator.
http://php.net/manual/en/function.set-error-handler.php
Also removing E_STRICT from the error_reporting config could fail, if the error occurs in the same file where error_reporting(...) (or ini_set('error_reporting, ...')) is called.
You mentioned you're using a framework (would be good to know which one) anyway you can add something like this on the very first index.php:
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('display_errors', 'On');
But make sure you're on the first index.php that gets called, meaning the very first in the stack, for certain framework that would save you some pain.
Other thing: most of the frameworks have their own config file to address production software VS. development software and they have their own way of doing things, so I would start from there....have a look at the docs and find out if there's anything there you need to change...it could be a super simple change on a config file most likely.
I was installing CMS Made simple when I ran into that error but here is how I over came it:
1) Open your php.ini file using any of your favorite editors;notepad, notepad++ or dreamweaver.
2) Press ctrl+f to fire up the find Dialog Box.
3) Type E_STRICT and click ok to jump you to the E_STRICT Line, there several E_STRICT Stuff but look for one with this kind of setting;
Common Values:
E_ALL & ~E_NOTICE (Show all errors, except for notices and coding standards warnings.)
E_ALL & ~E_NOTICE | E_STRICT (Show all errors, except for notices)
E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors)
E_ALL | E_STRICT (Show all errors, warnings and notices including coding standards.)
Default Value: E_ALL & ~E_NOTICE
Development Value: E_ALL | E_STRICT
Production Value: E_ALL & ~E_DEPRECATED
http://php.net/error-reporting
error_reporting = E_ALL , here the value with out the ";" is what matters so I just cleared it to:
error_reporting = (delete) and removed the E_ALL, and saved the file, I restarted all the services, and everything worked fine.
Hope that works for you too!.
error_reporting(E_ALL & ~E_STRICT);
I need to setup my PHP script at the top to disable error reporting for strict standards.
Can anybody help ?
Do you want to disable error reporting, or just prevent the user from seeing it? It’s usually a good idea to log errors, even on a production site.
# in your PHP code:
ini_set('display_errors', '0'); # don't show any errors...
error_reporting(E_ALL | E_STRICT); # ...but do log them
They will be logged to your standard system log, or use the error_log directive to specify exactly where you want errors to go.
For no errors.
error_reporting(0);
or for just not strict
error_reporting(E_ALL ^ E_STRICT);
and if you ever want to display all errors again, use
error_reporting(-1);
All above solutions are correct. But, when we are talking about a normal PHP application, they have to included in every page, that it requires. A way to solve this, is through .htaccess at root folder.
Just to hide the errors. [Put one of the followling lines in the file]
php_flag display_errors off
Or
php_value display_errors 0
Next, to set the error reporting
php_value error_reporting 30719
If you are wondering how the value 30719 came, E_ALL (32767), E_STRICT (2048) are actually constant that hold numeric value and (32767 - 2048 = 30719)
The default value of error_reporting flag is E_ALL & ~E_NOTICE if not set in php.ini.
But in some installation (particularly installations targeting development environments) has E_ALL | E_STRICT set as value of this flag (this is the recommended value during development). In some cases, specially when you'll want to run some open source projects, that was developed prior to PHP 5.3 era and not yet updated with best practices defined by PHP 5.3, in your development environment, you'll probably run into getting some messages like you are getting. The best way to cope up on this situation, is to set only E_ALL as the value of error_reporting flag, either in php.ini or in code (probably in a front-controller like index.php in web-root as follows:
if(defined('E_STRICT')){
error_reporting(E_ALL);
}
In php.ini set :
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT
WordPress
If you work in the wordpress environment, Wordpress sets the error level in file wp-includes/load.php in function wp_debug_mode(). So you have to change the level AFTER this function has been called ( in a file not checked into git so that's development only ), or either modify directly the error_reporting() call
I didn't see an answer that's clean and suitable for production-ready software, so here it goes:
/*
* Get current error_reporting value,
* so that we don't lose preferences set in php.ini and .htaccess
* and accidently reenable message types disabled in those.
*
* If you want to disable e.g. E_STRICT on a global level,
* use php.ini (or .htaccess for folder-level)
*/
$old_error_reporting = error_reporting();
/*
* Disable E_STRICT on top of current error_reporting.
*
* Note: do NOT use ^ for disabling error message types,
* as ^ will re-ENABLE the message type if it happens to be disabled already!
*/
error_reporting($old_error_reporting & ~E_STRICT);
// code that should not emit E_STRICT messages goes here
/*
* Optional, depending on if/what code comes after.
* Restore old settings.
*/
error_reporting($old_error_reporting);