rfc:deprecated_attribute
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:deprecated_attribute [2020/12/19 10:07] – beberlei | rfc:deprecated_attribute [2023/05/22 19:34] (current) – Fix a couple typos theodorejb | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: # | ====== PHP RFC: # | ||
- | * 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 |
+ | |||
+ | 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 | + | When this attribute |
- | This functionality is present for internal functions already. The Deprecaed | + | This functionality is present for internal functions already. The Deprecated |
<code php> | <code php> | ||
Line 46: | Line 48: | ||
</ | </ | ||
- | 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/ | 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/ | ||
- | 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' |
+ | |||
+ | 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