How to disable E_STRICT - php

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);

Related

Is the following the correct way to disable both E_WARNING and E_NOTICE in PHP

From http://php.net/manual/en/function.error-reporting.php, I know the correct way to disable E_NOTICE in PHP is
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
I was wondering, is the following the correct way to disable both E_WARNING and E_NOTICE in PHP?
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
That would do what you describe (turn off warnings and notices), yes. But if you actually want to turn off everything—which is highly recommended in production code—just use error_reporting(0);. There are many types of errors, warnings, and notices defined in PHP—and thus included in E_ALL*—that are not covered by E_NOTICE or E_WARNING.
From the docs
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.
As of 5.4, all errors, notices, and warnings covered by any predefined E_* constant are included in E_ALL. See the docs.
You can Use just simply that on your page.
error_reporting(0);

Can't get php errors to show when `error_reporting` set to `E_ALL`

I have WAMP with php 5.4.12 and I want to report errors.
My php.ini contains the following:
; 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
but no errors are showing.
What value should error_reporting take and how can I retrieve the reported errors?
I guess display_errors is turned off in your php.ini. Try the following instead (in the php file you are working on).
ini_set('display_errors' , 'On');
error_reporting(E_ALL);
For setting the flag on from php.ini, locate where display_errors is and change the value to On. Post your full php.ini if this does not work.
Can you check whether any error reporting flag in the php script(which will overwrite the php ini flags) in which you are trying to run and also in the .htaccess file. These are the two options which overwrites the php .ini flags.

Turning off Deprecation warnings in PHP.ini file WAMP

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.

Why would PHP report errors in my Include that aren't really errors?

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

Unable to turn off notice errors in PHP 5.3.2

I recently migrated to PHP 5.3.2, and realized that I am unable to turn off notice errors in my site now. I went to php.ini, and in these lines:
; 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 & ~E_NOTICE
...I've tried setting everything (and I restart apache each time), but I am unable to get rid of notices.
The only way I'm able to get rid of notice errors is by setting :
display_errors = Off
That is, of course, not something I can do since I need to see errors to fix them, and I would like to see errors on the webpage that I am coding rather than log them somewhere.
Can someone help? Is this a bug in PHP 5.3.2 or something I am doing wrong?
Thank you very much for your time!
P. S. Also, would anyone know how I can get PHP 5.3.2 to support the .php3 extension?
Okay, I figured what was going wrong. I set error_reporting in my code, which was overwriting the php.ini error_reporting.
Now the reason that that same stuff was working until I upgraded to PHP 5.3.2 was this - in my code, I set the error_reporting command:
error_reporting(6143);
I should've set it as:
error_reporting(E_ALL ^ E_NOTICE);
I'm guessing the meaning of 6143 is different in PHP 5.3.2 compared to in 4.1 (or whatever my earlier version was).
As for the php3 extension, it was to be set in the /etc/httpd/conf.d/php.conf file:
AddHandler php5-script .php .php3
AddType text/html .php
Thank you, sourcez, for your suggestions!
I too faced same error today in my website where i use TCPDF Library to generate PDFs. It was working fine but suddenly i started to get the following error today
Severity: 8192
Message: Imagick::clone method is deprecated .....
Might be the hosting provider updated PHP or Imagick. PHP - 5.4 and Imagick - 3.x
So to get rid of this in my code, i set error_reporting as
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
And this will show the errors but not the deprecated notices. Meanwhile I can change my code to support the new version of Imagick.

Categories