Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling Strict Standards in PHP 5.4

I'm currently running a site on php 5.4, prior to this I was running my site on 5.3.8. Unfortunately, php 5.4 combines E_ALL and E_STRICT, which means that my previous setting for error_reporting does not work now. My previous value was E_ALL & ~E_NOTICE & ~E_STRICT Should I just enable values one at a time?

I have far too many errors and the files contain too much code for me to fix.

like image 657
icomrade Avatar asked Apr 02 '12 20:04

icomrade


People also ask

How to turn off strict mode in php?

Hi just to make it little ease, for those who are using wamp, you can disable errors by clicking php > php settings >> display errors. If it is checked then uncheck it.

What is php strict standards?

Strict warnings are sent by PHP when certain old features are used or some code doesn't otherwise adhere to php's strict standards. In general, these errors are only helpful in development and can be ignored in production. In PHP 5.4, the E_STRICT error type was set to output by default.

How do I turn off php errors?

To turn off or disable error reporting in PHP, set the value to zero. For example, use the code snippet: <? php error_reporting(0); ?>

How do I turn off warnings in php INI?

Remember, the PHP ini configuration has an error_reporting directive that will be set by this function during runtime. error_reporting(0); To remove all errors, warnings, parse messages, and notices, the parameter that should be passed to the error_reporting function is zero.


2 Answers

As the commenters have stated the best option is to fix the errors, but with limited time or knowledge, that's not always possible. In your php.ini change

error_reporting = E_ALL 

to

error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT 

If you don't have access to the php.ini, you can potentially put this in your .htaccess file:

php_value error_reporting 30711 

This is the E_ALL value (32767) and the removing the E_STRICT (2048) and E_NOTICE (8) values.

If you don't have access to the .htaccess file or it's not enabled, you'll probably need to put this at the top of the PHP section of any script that gets loaded from a browser call:

error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE); 

One of those should help you be able to use the software. The notices and strict stuff are indicators of problems or potential problems though and you may find some of the code is not working correctly in PHP 5.4.

like image 152
David Stockton Avatar answered Oct 03 '22 20:10

David Stockton


.htaccess php_value is working only if you use PHP Server API as module of Web server Apache. Use IfModule syntax:

# PHP 5, Apache 1 and 2. <IfModule mod_php5.c>     php_value error_reporting 30711 </IfModule> 

If you use PHP Server API CGI/FastCGI use

ini_set('error_reporting', 30711); 

or

error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE); 

in your PHP code, or PHP configuration files .user.ini | php.ini modification:

error_reporting = E_ALL & ~E_STRICT & ~E_NOTICE 

on your virtual host, server level.

like image 33
Taras Avatar answered Oct 03 '22 20:10

Taras