rfc:deprecated_attribute

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:deprecated_attribute [2020/12/19 10:07] beberleirfc:deprecated_attribute [2023/05/22 19:34] (current) – Fix a couple typos theodorejb
Line 1: Line 1:
 ====== PHP RFC: #[Deprecated] Attribute ====== ====== PHP RFC: #[Deprecated] Attribute ======
  
-  * Version: 1.1+  * Version: 1.2-dev
   * Date: 2020-05-06   * Date: 2020-05-06
   * Author: Benjamin Ebelei    * Author: Benjamin Ebelei 
Line 9: Line 9:
 ===== Introduction ===== ===== Introduction =====
  
-With the Attributes RFC accepted for PHP 8, this is a first proposal for an internal attribute hooking into the engine. It allows to mark functions and methods as deprecated with the same mechanism that the engine and extensions already support for many years.+With the Attributes RFC accepted for PHP 8, this is a proposal for an internal attribute hooking into the engine. It allows to mark functions and methods as deprecated with the same mechanism that the engine and extensions already support for internal functions and methods for many years
 + 
 +The benefit of using a declarative attribute to mark deprecations over either docblock, trigger_error or a combination of both is that it provides both a human and a machine readable note about deprecation. This allows human readers, static analysis tools, IDEs and the runtime of PHP to rely on a single bit of information instead of multiple different ones.
  
 It also serves as a good prototype and first step, as usually all languages with attributes also have a Deprecated attribute in their language core. It also serves as a good prototype and first step, as usually all languages with attributes also have a Deprecated attribute in their language core.
Line 22: Line 24:
 For now is not possible to target classes, constants, properties or arguments with this attribute, and it is left for future RFC(s) to address this. For now is not possible to target classes, constants, properties or arguments with this attribute, and it is left for future RFC(s) to address this.
  
-Using attribute will add "ZEND_ACC_DEPERACTED" function flag to the op_array (userland function), which will automatically (with only small changes to the VM) lead to a deprecation warningwhen the function is called. +When this attribute is present, during the compile step the existing "ZEND_ACC_DEPERACTED" function flag is added to the op_array (userland function), which will lead to a deprecation warning when the function is called at runtime, with only minimal changes in the VM.
  
-This functionality is present for internal functions already. The Deprecaed attribute allows to expose this feature to userland functions/methods and closes a gap between internal and userland functions.+This functionality is present for internal functions already. The Deprecated attribute allows to expose this feature to userland functions/methods and closes a gap between internal and userland functions.
  
 <code php> <code php>
Line 46: Line 48:
 </code> </code>
  
-The deprecated class is final and cannot be extended.+The deprecated class is final and cannot be extended. The reason for this is that the engine internally cannot autoload attributes, so checking for a subclass that extends the Deprecated class is not technically possible. Marking the class as final prevents this.
  
 ==== Runtime Effects ==== ==== Runtime Effects ====
Line 52: Line 54:
 Using the deprecated attribute on a function or method behaves the same as putting a call to trigger_error using E_DEPRECATED level as the first line of the same function/method.  Using the deprecated attribute on a function or method behaves the same as putting a call to trigger_error using E_DEPRECATED level as the first line of the same function/method. 
  
-While other languages have deprecation attributes, they usually generate compile time warnings instead of runtime warnings. However as PHPs current deprecation model is based on runtime warnings, the Deprecation attribute builds on that existing model. The benefit of a declarative approach with an attribute over the current approach with a function call to trigger_error is that is that it abstracts the implementation details of how deprecations work, with the potential for better integration with future changes to the runtime warning stack of PHP.+While other languages have deprecation attributes, they usually generate compile time warnings instead of runtime warnings. However as PHP'current deprecation model is based on runtime warnings, the Deprecation attribute builds on that existing model. The benefit of a declarative approach with an attribute over the current approach with a function call to trigger_error is that is that it abstracts the implementation details of how deprecations work, with the potential for better integration with future changes to the runtime warning stack of PHP
 + 
 +This feature adds a small bitmask check in the VM for every function call.
  
 Changes to the runtime warning stack of PHP are out of the scope of this RFC. Changes to the runtime warning stack of PHP are out of the scope of this RFC.
rfc/deprecated_attribute.1608372420.txt.gz · Last modified: 2020/12/19 10:07 by beberlei