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 22:47] – beberlei | rfc:deprecated_attribute [2024/04/19 09:01] (current) – timwolla | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: # | + | ====== PHP RFC: #[\Deprecated] Attribute ====== |
- | * 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 | ||
- | <<Deprecated>> | + | use Deprecated; |
+ | |||
+ | # | ||
function test() {} | function test() {} | ||
// Deprecated: Function test() is deprecated | // Deprecated: Function test() is deprecated | ||
- | <<Deprecated(" | + | #[Deprecated(" |
function test2() {} | function test2() {} | ||
// Deprecated: Function test2() is deprecated, use test3() instead | // Deprecated: Function test2() is deprecated, use test3() instead | ||
class Foo { | class Foo { | ||
- | | + | |
public function test() {} | public function test() {} | ||
// Deprecated: Method Foo::test() is deprecated in %s | // Deprecated: Method Foo::test() is deprecated in %s | ||
} | } | ||
</ | </ | ||
+ | |||
+ | 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 ==== | ||
+ | |||
+ | 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 PHP's 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. | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | A class with the name " | + | < |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | 8.1 for function/ | + | Next minor (PHP 8.4). |
===== RFC Impact ===== | ===== RFC Impact ===== | ||
+ | |||
==== To SAPIs ==== | ==== To SAPIs ==== | ||
- | None | + | |
+ | None. | ||
==== To Existing Extensions ==== | ==== To Existing Extensions ==== | ||
- | None | + | |
+ | None. | ||
==== To Opcache ==== | ==== To Opcache ==== | ||
- | None | + | None. |
==== New Constants ==== | ==== New Constants ==== | ||
- | None | + | None. |
==== php.ini Defaults ==== | ==== php.ini Defaults ==== | ||
- | None | + | None. |
===== 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 ===== | ||
- | Accept # | + | <doodle title=" |
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | https:// | + | https:// |
+ | |||
+ | ===== Implementation ===== | ||
+ | |||
+ | n/a | ||
+ | |||
+ | ===== References ===== | ||
+ | |||
+ | * Implementation: | ||
+ | * Early Mailing List Discussion: https:// | ||
+ | |||
+ | ===== Rejected Features ===== | ||
- | No implementation for deprecated class constants, properties and parameters yet. | + | n/a |
rfc/deprecated_attribute.1608331621.txt.gz · Last modified: 2020/12/18 22:47 by beberlei