2015-10-04 16 views

回答

1

在PHP 5.4中,使用E_STRICT和E_ALL有什麼區別。

嗯:

5.4.0 E_STRICT became part of E_ALL. 
5.3.0 E_DEPRECATED and E_USER_DEPRECATED introduced. 
5.2.0 E_RECOVERABLE_ERROR introduced. 
5.0.0 E_STRICT introduced (not part of E_ALL). 

爲例:

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

?> 

PHP Manual: error_reporting

A similar question answered on SO here as well.

0

E_ALL會顯示錯誤的所有水平,E_STRICT介紹PHP 5.0將顯示建議/不嚴格的編碼標準/最佳實踐。由於PHP 5.4 E_STRICT已包含在E_ALL中。

基於PHP手冊:

在PHP 5新的誤差水平E_STRICT是可用的。在PHP 5.4.0之前,E_STRICT未包含在E_ALL中,因此您必須在PHP < 5.4.0中明確啓用此類錯誤級別。在開發過程中啓用E_STRICT有一些好處。 STRICT消息提供的建議可以幫助確保代碼的最佳互操作性和向前兼容性。這些消息可能包括諸如靜態調用非靜態方法,在使用特徵中定義的兼容類定義中定義屬性,以及PHP 5.3之前的一些不推薦使用的功能會發出E_STRICT錯誤,例如在實例化時通過引用分配對象。