¿Cómo desactivo los Avisos de PHP?


Notice: Constant DIR_FS_CATALOG already defined

Ya he comentado display_errors en php.ini, pero no está funcionando.

¿Cómo hago que PHP no muestre tales cosas a los navegadores?

ACTUALIZACIÓN

Puse display_errors = Off allí pero todavía está reportando tales avisos,

¿Es esto un problema con PHP 5.3?

Reportando numerosas Pila de llamadas también..

Author: Charles, 2010-05-19

14 answers

Puede establecer display_errors a 0 o utilizar el error_reporting() la función.

Sin embargo, los avisos son molestos (puedo en parte simpatizar) pero sirven a un propósito. No debe definir una constante dos veces, la segunda vez no funcionará y la constante permanecerá sin cambios!

 68
Author: Pekka 웃,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:26:36

De la documentación de PHP ( error_reporting):

<?php
// Turn off all error reporting
error_reporting(0);
?>

Otras opciones interesantes para esa función:

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

?>
 203
Author: Cristian,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-18 09:41:17

Para la línea de comandos php, establezca

error_reporting = E_ALL & ~E_NOTICE

En /etc/php5/cli/php.ini

Comando php ejecución luego ommits los avisos.

 26
Author: Paul Salber,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-11-06 02:18:20
<?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);

?>

Fuente http://php.net/manual/en/function.error-reporting.php

 20
Author: Abhishek Goel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-09 05:28:47

Usó Esta Línea En Su Código

error_reporting(E_ALL ^ E_NOTICE);  

Creo que está lleno para ti.

 5
Author: vicky mahale,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-13 09:48:12

Puede establecer ini_set('display_errors',0); en su script o definir qué errores desea mostrar con error_reporting().

 4
Author: jeroen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-05-19 15:44:41

Al no causar los errores:

defined('DIR_FS_CATALOG') || define('DIR_FS_CATALOG', 'whatever');

Si realmente tiene que hacerlo, entonces cambie el reporte de errores usando error_reporting() a E_ALL^E_NOTICE.

 3
Author: Jonathan Kuhn,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-05-19 15:46:00

Usted está buscando:

php -d error_reporting="E_ERROR | E_WARNING | E_PARSE"
 3
Author: Christian Tismer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-10-07 20:06:35

Para el código PHP:

<?php
error_reporting(E_ALL & ~E_NOTICE);

Para php.ini config:

error_reporting = E_ALL & ~E_NOTICE
 2
Author: Nabi K.A.Z.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-09 13:14:48

Puedes comprobar si la constante ya está definida usando:

<?php
if (!defined('MYCONST'))
    define('MYCONST', 'Weeha!');
?>
 0
Author: Thiago Belem,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-05-19 15:46:09

Creo que comentando display_errors en php.ini no funcionará porque el valor predeterminado está activado. Debes ponerlo en ' Off ' en su lugar.

No olvide reiniciar Apache para aplicar cambios de configuración.

También tenga en cuenta que si bien puede establecer display_errors en tiempo de ejecución, cambiarlo aquí no afecta a los errores FATALES.

Como han señalado otros, lo ideal es que durante el desarrollo se ejecute con error_reporting al nivel más alto posible y display_errors habilitado. Mientras molesto cuando usted en primer lugar, estos errores, advertencias, avisos y estrictos consejos de codificación se suman y le permiten convertirse en un mejor codificador.

 0
Author: AllenJB,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-05-19 15:58:05

Encontré este truco recientemente. Golpea una @ al comienzo de una línea que puede producir una advertencia/error.

Como por arte de magia, desaparecen.

 0
Author: DrLazer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-05-19 16:00:57

Use phpinfo() y busque Configuration File (php.ini) Path para ver qué ruta de archivo de configuración se usa para php. PHP puede tener varios archivos de configuración dependiendo del entorno en el que se esté ejecutando. Por lo general, para la consola es:

/etc/php5/cli/php.ini

Y para php ejecutado por apache es:

/etc/php5/apache2/php.ini

Y luego establece error_reporting la forma que necesitas 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

 0
Author: MilanG,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-04 07:56:40

Como han mencionado algunos y si usted es el autor del código, debe corregir todos esos errores, avisos, etc. porque causará más problemas a largo plazo que no arreglarlos (especialmente cuando actualice su sistema operativo). Para su servidor, debe tener errores mostrados solo en sus registros, no en la pantalla del cliente.

Así que para evitar los errores en tu navegador utilizas la bandera display_errors como ya has encontrado:

display_errors = Off

Ahora el verdadero problema es cuando estás ejecutando a alguien más codificar. En ese caso, es probable que la modificación del código se sobrescriba cada vez que actualice ese código. Hace que sea tedioso mantener ese código.

En mi caso, estoy ejecutando PHP con crontab para tener el script wp-cron.php ejecutándose de vez en cuando. ¡Estaba recibiendo errores enviados a mis correos electrónicos, lo que se vuelve tedioso cuando recibe un correo electrónico cada 10 minutos! En ese caso, sin embargo, el sistema de Wordpress tiene un archivo de configuración incluye un WP_DEBUG y llaman a la función error_reporting() así que tratando de cambiar el error_reporting variable en la línea de comandos no funcionará. En su lugar, debe editar el archivo wp-config.php en la carpeta raíz y asegurarse de que WP_DEBUG esté establecido en false. De lo contrario, recibirá todas esas advertencias y avisos todo el tiempo.

 0
Author: Alexis Wilke,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-04 06:44:28