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 08:52] – beberlei | rfc:deprecated_attribute [2024/04/23 17:05] (current) – Formatting: wrap @deprecated with <php>/** */</php> levim | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: # | + | ====== PHP RFC: #[\Deprecated] Attribute ====== |
- | * Version: 1.1 | + | * Version: 1.3 |
- | * 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 | + | PHP’s internal functions can be marked as deprecated, making |
- | It also serves as a good prototype and first step, as usually all languages | + | While the functionality can be // |
===== Proposal ===== | ===== Proposal ===== | ||
- | <nowiki>Developers can put an attribute | + | A new attribute |
- | * Functions | ||
- | * Methods | ||
- | For now is not possible to target classes, constants, | + | < |
+ | /** | ||
+ | * @strict-properties | ||
+ | */ | ||
+ | #[Attribute(Attribute:: | ||
+ | final class Deprecated | ||
+ | { | ||
+ | public readonly ?string $message; | ||
- | Using attribute will add " | + | public |
+ | } | ||
+ | </ | ||
- | This functionality is present for internal functions already. The Deprecaed | + | Applying this attribute to a userland function or method will add the internal '' |
- | <code php> | + | * <php> |
+ | * Calling the function will emit a < | ||
+ | |||
+ | The <php> | ||
+ | |||
+ | ==== Examples ==== | ||
+ | |||
+ | <PHP> | ||
<?php | <?php | ||
- | use Deprecated; | + | #[\Deprecated] |
+ | function test() { | ||
+ | } | ||
- | # | + | #[\Deprecated("use test() instead" |
- | function | + | function |
- | // Deprecated: Function test() is deprecated | + | } |
- | # | + | class Clazz { |
- | function | + | |
- | // Deprecated: Function test2() is deprecated, use test3() instead | + | function |
+ | | ||
- | class Foo { | + | |
- | | + | function |
- | | + | |
- | | + | |
} | } | ||
- | </ | ||
- | The deprecated | + | test(); // Deprecated: Function test() is deprecated |
+ | test2(); // Deprecated: Function test2() | ||
+ | call_user_func(" | ||
- | ==== Runtime Effects ==== | + | $cls = new Clazz(); |
+ | $cls-> | ||
+ | $cls-> | ||
- | Using the deprecated | + | call_user_func([$cls, |
- | 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 concept is extended instead of inventing another approach. | + | ?> |
+ | </ | ||
- | Changing deprecation warnings from runtime to a different approach falls out of the scope of this RFC. | + | < |
+ | <?php | ||
+ | |||
+ | # | ||
+ | function test() { | ||
+ | } | ||
+ | |||
+ | $r = new ReflectionFunction(' | ||
+ | |||
+ | var_dump($r-> | ||
+ | |||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | <?php | ||
+ | |||
+ | # | ||
+ | function test1() { | ||
+ | } | ||
+ | |||
+ | # | ||
+ | function test2() { | ||
+ | } | ||
+ | |||
+ | # | ||
+ | function test3() { | ||
+ | } | ||
+ | |||
+ | $reflection = new ReflectionFunction(' | ||
+ | var_dump($reflection-> | ||
+ | /* | ||
+ | object(Deprecated)# | ||
+ | [" | ||
+ | NULL | ||
+ | } | ||
+ | */ | ||
+ | |||
+ | $reflection = new ReflectionFunction(' | ||
+ | var_dump($reflection-> | ||
+ | /* | ||
+ | object(Deprecated)# | ||
+ | [" | ||
+ | NULL | ||
+ | } | ||
+ | */ | ||
+ | |||
+ | $reflection = new ReflectionFunction(' | ||
+ | var_dump($reflection-> | ||
+ | /* | ||
+ | object(Deprecated)# | ||
+ | [" | ||
+ | string(18) "use test() instead" | ||
+ | } | ||
+ | */ | ||
+ | |||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | Further examples are given by [[https:// | ||
===== 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 | + | |
+ | The < | ||
+ | |||
+ | For extensions that are part of php-src the attribute will replace the existing doc comment as part of this RFC. | ||
==== 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 ===== | ||
+ | |||
+ | * Supporting < | ||
+ | * Adding further metadata to the < | ||
===== 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 | + | * Changes to the runtime behavior of deprecated |
+ | * Making the < |
rfc/deprecated_attribute.1608367955.txt.gz · Last modified: 2020/12/19 08:52 by beberlei