簡體   English   中英

PHP 5.4中的E_STRICT和E_ALL有什么區別?

[英]What is the difference between E_STRICT and E_ALL in PHP 5.4?

在PHP 5.4中,使用E_STRICTE_ALL什么區別?

兩者都一樣嗎?

在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手冊:error_reporting

這里也回答了類似的問題。

E_ALL將顯示所有級別的錯誤,PHP 5.0上引入的E_STRICT將顯示嚴格編碼標准/最佳實踐的建議/通知。 由於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錯誤,例如在實例化時通過引用分配對象。

暫無
暫無

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

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