簡體   English   中英

關閉 PHP 5.3 中棄用的錯誤

[英]Turn off deprecated errors in PHP 5.3

我的服務器正在運行 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

這很煩人,但我不想關閉屏幕錯誤報告。 如何禁用這些煩人的棄用警告?

我正在運行 WordPress 2.9.2。

您可以通過調用以下函數在代碼中完成。

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

或者

error_reporting(E_ALL ^ E_DEPRECATED);

我需要適應這個

error_reporting = E_ALL & ~E_DEPRECATED

要僅獲取導致應用程序停止工作的那些錯誤,請使用:

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

這將停止顯示通知、警告和已棄用的錯誤。

之前的所有答案都是正確的。 由於沒有人暗示過如何關閉 PHP 中的所有錯誤,我想在這里提一下:

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

有人可能會覺得它很有用...

我剛剛遇到了一個類似的問題,一個 SEO 插件發出了大量警告,使我的博客磁盤使用超出了計划限制。

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

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

通過這樣做,您的錯誤日志文件中不會再有警告、通知或不推薦使用的行!

在 WordPress 3.8 上測試過,但我想它適用於每個安裝。

在文件 wp-config.php 中,您可以找到常量 WP_DEBUG。 確保將其設置為 false。

define('WP_DEBUG', false);

這適用於 WordPress 3.x。

您必須編輯 PHP 配置文件。 找到線

error_reporting = E_ALL

並將其替換為:

error_reporting = E_ALL ^ E_DEPRECATED

如果您無權訪問配置文件,則可以將此行添加到 PHP WordPress 文件(可能是 headers.php)中:

error_reporting(E_ALL ^ E_DEPRECATED);

我傾向於使用這種方法

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

這樣我就不會意外關閉我需要的東西

如果 PHP 警告破壞了 WordPress 中的內容,但您仍然想知道警告是什么,您可以禁用顯示 PHP 錯誤/警告,只將它們發送到日志文件:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'WP_DEBUG_LOG', true );

當您更改 php 版本時會發生此錯誤:抑制此錯誤消息非常簡單

要抑制 DEPRECATED 錯誤消息,只需將以下代碼添加到您的 index.php 文件中:

init_set('display_errors',False);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM