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/18 23:01] – beberlei | rfc:deprecated_attribute [2024/04/15 13:00] (current) – beberlei | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: # | ====== PHP RFC: # | ||
- | * Version: 1.1 | + | * Version: 1.3-dev |
- | * Date: 2020-05-06 | + | * Date: 2024-04-15 |
- | * Author: Benjamin | + | * Author: Benjamin |
* Status: Under Discussion | * Status: Under Discussion | ||
* First Published at: http:// | * First Published at: http:// | ||
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. | + | 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 15: | Line 17: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | < | + | < |
* Functions | * Functions | ||
* Methods | * Methods | ||
- | It is not possible to target classes, constants, properties or arguments | + | For now is not possible to target classes, constants, properties or arguments |
- | Using attribute | + | When this attribute |
+ | |||
+ | The ZEND_ACC_DEPRECATED flag and behavior | ||
+ | |||
+ | For userland functions the E_USER_DEPRECATED level is used, instead of the E_DEPRECATED that is raised for internal | ||
<code php> | <code php> | ||
<?php | <?php | ||
+ | |||
+ | use Deprecated; | ||
# | # | ||
Line 41: | Line 49: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | 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 that users extend the class and expect their children exhibit the same behavior. | ||
==== Runtime Effects ==== | ==== Runtime Effects ==== | ||
Line 46: | Line 56: | ||
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 existing | + | While other languages have deprecation attributes, they usually generate compile time warnings instead of runtime warnings. However as PHP' |
- | Changing deprecation warnings from runtime to a different approach falls out of the scope of this RFC. | + | 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. | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 56: | Line 68: | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | 8.1 for function/ | + | 8.4 for function/ |
===== RFC Impact ===== | ===== RFC Impact ===== | ||
Line 79: | Line 91: | ||
===== Open Issues ===== | ===== Open Issues ===== | ||
- | A few things tracked in https:// | + | A few things tracked in https:// |
+ | |||
+ | ===== Future Scope ===== | ||
+ | |||
+ | * Allowing # | ||
+ | * Adding further metadata to the Deprecated attribute beyond a custom message, such as hints for replacements that IDEs could use. | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== |
rfc/deprecated_attribute.1608332508.txt.gz · Last modified: 2020/12/18 23:01 by beberlei