rfc:magic-methods-signature
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:magic-methods-signature [2020/04/26 18:19] – Add old serialize methods changes carusogabriel | rfc:magic-methods-signature [2020/08/01 23:34] (current) – Move RFC to Implemented carusogabriel | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Ensure correct magic methods' signatures when typed ====== | + | ====== PHP RFC: Ensure correct |
* Version: 1.0 | * Version: 1.0 | ||
* Date: 2020-04-05 | * Date: 2020-04-05 | ||
* Author: Gabriel Caruso (< | * Author: Gabriel Caruso (< | ||
- | * Status: | + | * Status: |
* Target Version: PHP 8.0 | * Target Version: PHP 8.0 | ||
* Implementation: | * Implementation: | ||
Line 9: | Line 9: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | This RFC is inspired by [[https:// | + | It is currently possible to write magic methods that have signatures that don't match the signature |
- | However, this implementation is not as simple as just check for the methods' | + | This behavior of allowing incorrect |
- | Nowadays, PHP already checks the signature for the following methods: | + | As ensuring magic methods have correct signatures is a backward compatible break for code that currently has incorrect signatures, this change would only be appropriate in a major PHP release. |
- | + | ||
- | * // | + | |
- | * // | + | |
- | * // | + | |
- | * // | + | |
===== Motivation ===== | ===== Motivation ===== | ||
Line 24: | Line 19: | ||
PHP's Magic Methods is something that PHP provides allowing developers to track and act on specific changes of behavior of a certain class. Given that fact, the same should ensure that the end-users are using these methods consistently across different codebases. | PHP's Magic Methods is something that PHP provides allowing developers to track and act on specific changes of behavior of a certain class. Given that fact, the same should ensure that the end-users are using these methods consistently across different codebases. | ||
- | Since the introduction of types in PHP 7.0, only the checks | + | Since the introduction of types in PHP 7.0, only the checks |
+ | |||
+ | * // | ||
+ | * // | ||
+ | * // | ||
+ | * // | ||
For PHP 8, this RFC aims to expand these checks. | For PHP 8, this RFC aims to expand these checks. | ||
Line 30: | Line 30: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC proposes to introduce | + | This RFC proposes to add parameter and return types checks per the following |
- | + | ||
- | **Important: | + | |
The proposal follows the [[https:// | The proposal follows the [[https:// | ||
<code php> | <code php> | ||
- | /** @return mixed */ | + | Foo:: |
- | Foo:: | + | |
- | /** @return mixed */ | + | Foo:: |
- | Foo:: | + | |
Foo:: | Foo:: | ||
- | Foo:: | + | Foo:: |
- | /** @return mixed */ | + | Foo:: |
- | Foo:: | + | |
+ | Foo:: | ||
Foo:: | Foo:: | ||
Line 54: | Line 51: | ||
Foo:: | Foo:: | ||
- | /** @param mixed $value */ | + | Foo:: |
- | Foo:: | + | |
- | /** @return mixed */ | + | Foo:: |
- | Foo:: | + | |
Foo:: | Foo:: | ||
Line 69: | Line 64: | ||
</ | </ | ||
- | **Note:** The // | + | **Note:** The // |
| | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | |||
- | An important note here is that if one of the listed magic methods is directly called, and it has the wrong signatures, the error will be thrown regardless. | ||
- | |||
- | For example https:// | ||
==== To Magic Methods without types declared ==== | ==== To Magic Methods without types declared ==== | ||
Line 89: | Line 80: | ||
Scraping the top 1000 Composer packages (using Nikita' | Scraping the top 1000 Composer packages (using Nikita' | ||
- | Luckily, none of them is a problem as // | + | Luckily, none of them is a problem as // |
Even with a //mixed// RFC that wouldn' | Even with a //mixed// RFC that wouldn' | ||
Line 95: | Line 86: | ||
===== Future Scope ===== | ===== Future Scope ===== | ||
- | This RFC only aims to add checks for the methods' | + | This RFC only aims to add checks for the methods' |
+ | |||
+ | * // | ||
+ | * // | ||
+ | * // | ||
+ | * // | ||
+ | |||
+ | ===== Voting ===== | ||
- | ===== Proposed | + | Voting |
- | Yes/No. | + | <doodle title=" |
+ | | ||
+ | | ||
+ | </ | ||
===== External resources ===== | ===== External resources ===== |
rfc/magic-methods-signature.1587925154.txt.gz · Last modified: 2020/04/26 18:19 by carusogabriel