关闭 PHP 5.3 中已弃用的错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2803772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:43:00  来源:igfitidea点击:

Turn off deprecated errors in PHP 5.3

phpwordpressdeprecation-warning

提问by atwellpub

My server is running PHP 5.3 and my WordPress install is spitting these errors out on me, causing my session_start() to break.

我的服务器正在运行 PHP 5.3,我的 WordPress 安装向我吐出这些错误,导致我的 session_start() 中断。

Deprecated: Assigning the return value of new by reference is deprecated in /home//public_html/hub/wp-settings.php on line 647

Deprecated: Assigning the return value of new by reference is deprecated in /home//public_html/hub/wp-settings.php on line 662

Deprecated: Assigning the return value of new by reference is deprecated in /home//public_html/hub/wp-settings.php on line 669

Deprecated: Assigning the return value of new by reference is deprecated in /home//public_html/hub/wp-settings.php on line 676

Deprecated: Assigning the return value of new by reference is deprecated in /home//public_html/hub/wp-settings.php on line 712

This is annoying, but I do not want to turn off on screen error reporting. How do I disable these bothersome deprecated warnings?

这很烦人,但我不想关闭屏幕错误报告。如何禁用这些令人讨厌的已弃用警告?

I am running WordPress 2.9.2.

我正在运行 WordPress 2.9.2。

回答by Robus

You can do it in code by calling the following functions.

您可以通过调用以下函数在代码中完成。

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

or

或者

error_reporting(E_ALL ^ E_DEPRECATED);

回答by Simon H

I needed to adapt this to

我需要适应这个

error_reporting = E_ALL & ~E_DEPRECATED

回答by codefreak

To only get those errors that cause the application to stop working, use:

要仅获取导致应用程序停止工作的那些错误,请使用:

error_reporting(E_ALL ^ (E_NOTICE | E_WARNING | E_DEPRECATED));

This will stop showing notices, warnings, and deprecated errors.

这将停止显示通知、警告和已弃用的错误。

回答by sudip

All the previous answers are correct. Since no one have hinted out how to turn off all errors in PHP, I would like to mention it here:

之前的所有答案都是正确的。由于没有人暗示过如何关闭 PHP 中的所有错误,我想在这里提一下:

error_reporting(0); // Turn off warning, deprecated,
                    // notice everything except error

Somebody might find it useful...

有人可能会觉得它很有用...

回答by Camaleo

I just faced a similar problem where a SEO plugin issued a big number of warnings making my blog disk use exceed the plan limit.

我刚刚遇到了一个类似的问题,一个 SEO 插件发出了大量警告,使我的博客磁盘使用超出了计划限制。

I found out that you mustinclude the error_reporting command afterthe wp-settings.php require in the wp-config.php file:

我发现您必须在 wp-config.php 文件中的 wp-settings.php 要求之后包含 error_reporting 命令:

   require_once( ABSPATH .'wp-settings.php' );
   error_reporting( E_ALL ^ ( E_NOTICE | E_WARNING | E_DEPRECATED ) );

by doing this no more warnings, notices nor deprecated lines are appended to your error log file!

通过这样做,您的错误日志文件中不再有警告、通知或不推荐使用的行!

Tested on WordPress 3.8 but I guess it works for every installation.

在 WordPress 3.8 上测试过,但我想它适用于每个安装。

回答by Audrius

In file wp-config.php you can find constant WP_DEBUG. Make sure it is set to false.

在文件 wp-config.php 中,您可以找到常量 WP_DEBUG。确保将其设置为 false。

define('WP_DEBUG', false);

This is for WordPress 3.x.

这适用于 WordPress 3.x。

回答by Kreker

You have to edit the PHP configuration file. Find the line

您必须编辑 PHP 配置文件。找到线

error_reporting = E_ALL

and replace it with:

并将其替换为:

error_reporting = E_ALL ^ E_DEPRECATED

error_reporting = E_ALL ^ E_DEPRECATED

If you don't have access to the configuration file you can add this line to the PHP WordPress file (maybe headers.php):

如果您无权访问配置文件,则可以将此行添加到 PHP WordPress 文件(可能是 headers.php)中:

error_reporting(E_ALL ^ E_DEPRECATED);

回答by realtebo

I tend to use this method

我倾向于使用这种方法

$errorlevel=error_reporting();
$errorlevel=error_reporting($errorlevel & ~E_DEPRECATED);

In this way I do not turn off accidentally something I need

这样我就不会意外关闭我需要的东西

回答by dheerendra

this error occur when you change your php version: it's very simple to suppress this error message

当您更改 php 版本时会发生此错误:抑制此错误消息非常简单

To suppress the DEPRECATED Error message, just add below code into your index.php file:

要抑制 DEPRECATED 错误消息,只需将以下代码添加到您的 index.php 文件中:

init_set('display_errors',False);

init_set('display_errors',False);