rfc:deprecated-modifier
Differences
This shows you the differences between two versions of the page.
rfc:deprecated-modifier [2012/12/25 19:08] pp3345 RFC created |
rfc:deprecated-modifier [2017/09/22 13:28] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Request for Comments: Add a deprecated modifier for functions ====== | ||
- | * Version: 1.0 | ||
- | * Date: 2012-12-25 | ||
- | * Author: Yussuf Khalil < | ||
- | * Status: Under Discussion | ||
- | * First Published at: https:// | ||
- | ===== Introduction ===== | ||
- | |||
- | This RFC proposes the addition of a " | ||
- | |||
- | ===== How can this be useful? ===== | ||
- | |||
- | It is common for large PHP frameworks to deprecate old functions and methods that are still in use (by plugins for example) when releasing new versions. Later, these functions will usually be completely removed. Native functions only need the ZEND_ACC_DEPRECATED flag and Zend will automatically throw an E_DEPRECATED error when they are called. However, a userspace function can only be deprecated by either adding the @deprecated tags to the doc comment or by throwing an E_USER_DEPRECATED error. Why does a userspace developer need to throw an error himself while a native function only needs a flag? | ||
- | |||
- | Simply deprecating a function by adding a deprecated modifier to the function declaration is cleaner, faster and more obvious for developers when looking at the function declaration. | ||
- | |||
- | Custom E_USER_DEPRECATED errors could rather be used for deprecating whole libraries or specific ways of calling a function. | ||
- | |||
- | Also, ReflectionFunction:: | ||
- | |||
- | ===== Examples ===== | ||
- | |||
- | <code php> | ||
- | deprecated function myFunction() { | ||
- | // ... | ||
- | } | ||
- | |||
- | myFunction(); | ||
- | </ | ||
- | |||
- | Deprecated: Function myFunction() is deprecated in ... on line 5 | ||
- | |||
- | <code php> | ||
- | class MyClass { | ||
- | public deprecated static function myMethod() { | ||
- | // ... | ||
- | } | ||
- | } | ||
- | |||
- | MyClass:: | ||
- | </ | ||
- | |||
- | Deprecated: Function MyClass:: | ||
- | |||
- | ===== Patch ===== | ||
- | |||
- | A pull request is available at https:// | ||
- | |||
- | This patch adds a T_DEPRECATED token and sets the ZEND_ACC_DEPRECATED flag for every function declaration preceded by this token. It properly checks for multiple deprecated modifiers or deprecated properties and throws an E_COMPILE_ERROR in these cases. | ||
- | |||
- | ===== Changelog ===== | ||
- | |||
- | - 2012-12-25 RFC created and published |
rfc/deprecated-modifier.txt · Last modified: 2017/09/22 13:28 (external edit)