PHP 공지를 끄려면 어떻게합니까?
Notice: Constant DIR_FS_CATALOG already defined
display_errors
에서 이미 댓글을 달았 php.ini
지만 작동하지 않습니다.
PHP가 그러한 것들을 브라우저에 출력하지 않도록하려면 어떻게해야합니까?
최신 정보
나는 display_errors = Off
거기에 넣었 지만 여전히 그러한 통지를보고하고있다.
이것은 PHP 5.3의 문제입니까?
수많은 통화 스택 도 보고합니다 ..
당신은 설정할 수 display_errors
로 0
또는 사용 error_reporting()
기능.
그러나 통지는 성가 시지만 ( 부분적으로 동정 할 수 있음 ) 목적을 제공합니다. 상수를 두 번 정의하면 안되며 두 번째는 작동하지 않으며 상수는 변경되지 않습니다!
PHP 문서에서 ( error_reporting ) :
<?php
// Turn off all error reporting
error_reporting(0);
?>
해당 기능에 대한 다른 흥미로운 옵션 :
<?php
// 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);
?>
커맨드 라인 PHP의 경우,
error_reporting = E_ALL & ~E_NOTICE
에 /etc/php5/cli/php.ini
php
그런 다음 명령 실행은 통지를 생략합니다.
<?php
// Turn off all error reporting
error_reporting(0);
// 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
error_reporting(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);
?>
소스 http://php.net/manual/en/function.error-reporting.php
이 줄을 코드에서 사용했습니다.
error_reporting(E_ALL ^ E_NOTICE);
나는 그 선반이 당신에게 가득 차 있다고 생각합니다.
ini_set('display_errors',0);
스크립트에서 설정 하거나로 표시하려는 오류를 정의 할 수 있습니다 error_reporting()
.
당신이 찾고있는:
php -d error_reporting="E_ERROR | E_WARNING | E_PARSE"
오류를 일으키지 않음으로써 :
defined('DIR_FS_CATALOG') || define('DIR_FS_CATALOG', 'whatever');
실제로 필요한 경우 error_reporting ()을 사용하여 오류보고를 E_ALL ^ E_NOTICE로 변경하십시오.
PHP 코드의 경우 :
<?php
error_reporting(E_ALL & ~E_NOTICE);
대한 php.ini
설정 :
error_reporting = E_ALL & ~E_NOTICE
error_reporting
내 코드를 설정하지 않는 것을 선호합니다 . 그러나 어떤 경우에는 레거시 제품인 경우 알림이 너무 많아 숨겨져 야합니다.
그래서 다음 스 니펫을 사용하여 서버 측 구성 값을 설정 error_reporting
하고 E_NOTICE
s를 뺍니다 .
error_reporting(error_reporting() & ~E_NOTICE);
Now the error reporting setting can further be configured in php.ini
or .htaccess
. Only notices will always be disabled.
You can check if the constant's already defined using:
<?php
if (!defined('MYCONST'))
define('MYCONST', 'Weeha!');
?>
I believe commenting out display_errors in php.ini won't work because the default is On. You must set it to 'Off' instead.
Don't forget to restart Apache to apply configuration changes.
Also note that while you can set display_errors at runtime, changing it here does not affect FATAL errors.
As noted by others, ideally during development you should run with error_reporting at the highest level possible and display_errors enabled. While annoying when you first start out, these errors, warnings, notices and strict coding advice all add up and enable you to becoem a better coder.
I found this trick out recently. Whack an @ at the start of a line that may produce an warning/error.
As if by magic, they dissapear.
Use phpinfo() and search for Configuration File (php.ini) Path
to see which config file path for php is used. PHP can have multiple config files depending on environment it's running. Usually, for console it's:
/etc/php5/cli/php.ini
and for php run by apache it's:
/etc/php5/apache2/php.ini
And then set error_reporting
the way you need it:
http://www.phpknowhow.com/configuration/php-ini-error-settings/ http://www.zootemplate.com/news-updates/how-to-disable-notice-and-warning-in-phpini-file
As mentioned by some and if you are the code author, you should correct all those errors, notices, etc. because it will cause more problems for you long terms than not fixing them (especially when you upgrade your OS). For your server, you should have errors displayed in your logs only, not the client's screen.
So to avoid the errors in your browser you use the display_errors
flag as you already found:
display_errors = Off
Now the real problem is when you are running someone else code. In that case, modifying the code is likely to get overwritten each time you upgrade that code. It makes it tedious to maintain that code.
In my case, I am running PHP with crontab
to have the wp-cron.php
script running once in a while. I was getting errors sent to my emails, which becomes tedious when you get one email every 10 minutes! In that case, though, the Wordpress system has a configuration file includes a WP_DEBUG
and they call the error_reporting()
function so trying to change the error_reporting
variable on the command line won't work. Instead you have to edit the wp-config.php
file in the root folder and make sure that the WP_DEBUG
is set to false
. Otherwise you will get all those warnings and notices all the time.
참고URL : https://stackoverflow.com/questions/2867057/how-do-i-turn-off-php-notices
'programing tip' 카테고리의 다른 글
Vim에서 f 및 t 명령은 무엇을합니까? (0) | 2020.07.26 |
---|---|
DIV 대신 테이블 (0) | 2020.07.26 |
tsconfig.json 파일을 어떻게 생성합니까? (0) | 2020.07.25 |
Apache POI에서 XSSF를 가져올 수 없습니다 (0) | 2020.07.25 |
Java 열거 형에서 valueof () 및 toString () 재정의 (0) | 2020.07.25 |