rfc:non_nullable_property_checks
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
rfc:non_nullable_property_checks [2019/01/24 18:54] – getting somewhere; not ready for discussion yet, though, I think imsop | rfc:non_nullable_property_checks [2019/01/24 22:15] (current) – imsop | ||
---|---|---|---|
Line 19: | Line 19: | ||
* a simpler contract, that the property *can only be set to* the given type | * a simpler contract, that the property *can only be set to* the given type | ||
- | When a property has a static default value, or allows nulls, the distinction rarely matters: in normal use, the property starts life with a valid value, and can only be set to a valid value; therefore, it will always have a valid value. However, if null is not a valid value, and there is no static default, the property must start in an invalid state, and it is easy to write code which leaves it in that state. | + | When a property has a static default value, or allows nulls, the distinction rarely matters: in normal use, the property starts life with a valid value, and can only be set to a valid value. However, if null is not a valid value, and there is no static default, the property must start in an invalid state, and it is easy to write code which leaves it in that state. |
The stronger contract requires extremely careful language design, as there must be some defined point in the program where the asserted state first becomes true; for instance, in [[https:// | The stronger contract requires extremely careful language design, as there must be some defined point in the program where the asserted state first becomes true; for instance, in [[https:// | ||
Line 38: | Line 38: | ||
case ' | case ' | ||
$this-> | $this-> | ||
+ | ### The bug is actually here | ||
break; | break; | ||
case ' | case ' | ||
Line 55: | Line 56: | ||
public function __construct() { | public function __construct() { | ||
$this-> | $this-> | ||
- | | + | ### Proposed TypeError: "Typed property $value must be initialized before end of constructor ... in ImplementationDetail:: |
} | } | ||
| | ||
Line 68: | Line 69: | ||
| | ||
echo $tool-> | echo $tool-> | ||
- | | + | ### Current TypeError: "Typed property $value must not be accessed before initialization ... in UsefulTool-> |
} | } | ||
</ | </ | ||
Line 86: | Line 87: | ||
* Immediately after an object is constructed (to catch errors in '' | * Immediately after an object is constructed (to catch errors in '' | ||
- | * Immediately after an object is deserialized | + | * Immediately after an object is unserialized |
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 93: | Line 94: | ||
If it is for some reason delayed, there is the possibility that code which runs under PHP 7.4 will start raising errors due to the new checks. | If it is for some reason delayed, there is the possibility that code which runs under PHP 7.4 will start raising errors due to the new checks. | ||
- | ===== Proposed PHP Version(s) | + | ===== Performance |
- | PHP 7.4 | + | |
- | ===== RFC Impact ===== | + | Although the checks will obviously have some overhead, this is expected to be close to zero for classes with no typed properties (since we can check using '' |
- | ==== To Existing Extensions ==== | ||
- | Will existing extensions be affected? | ||
- | ==== To Opcache | + | ===== Proposed PHP Version ===== |
- | It is necessary to develop RFC's with opcache in mind, since opcache is a core extension distributed with PHP. | + | PHP 7.4 |
- | + | ||
- | Please explain how you have verified your RFC's compatibility with opcache. | + | |
===== Open Issues ===== | ===== Open Issues ===== | ||
- | Make sure there are no open issues when the vote starts! | + | |
+ | * Are there other places that this assertion can be added? | ||
+ | * Should we expose '' | ||
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
- | List existing areas/ | ||
- | This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise. | + | It is important to understand |
+ | |||
+ | * Calling | ||
+ | * Creating an object with '' | ||
- | ===== Future Scope ===== | ||
- | This section details areas where the feature might be improved in future, but that are not currently proposed in this RFC. | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | Include these so readers know where you are heading and can discuss the proposed voting options. | + | **Should checks be added to detect objects which are not fully initialized after common cases such as construction.** |
- | State whether this project | + | This is a change to the behaviour of the language, so requires a 2/3 majority. |
===== Implementation ===== | ===== Implementation ===== | ||
- | TODO | + | None yet. |
===== References ===== | ===== References ===== | ||
Line 131: | Line 129: | ||
===== Rejected Features ===== | ===== Rejected Features ===== | ||
- | Keep this updated with features that were discussed on the mail lists. | + | TODO |
rfc/non_nullable_property_checks.1548356040.txt.gz · Last modified: 2019/01/24 18:54 by imsop