rfc:deprecate_dynamic_properties
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
rfc:deprecate_dynamic_properties [2021/11/15 13:47] – nikic | rfc:deprecate_dynamic_properties [2021/11/15 14:05] – Fix typos theodorejb | ||
---|---|---|---|
Line 31: | Line 31: | ||
==== Motivation ==== | ==== Motivation ==== | ||
- | The motivation for this change is twofold: To prevent mistakes (due to typos or renames) in the common case, and to make intentional uses explicit. The core problem is that reading from a non-existing property | + | The motivation for this change is twofold: To prevent mistakes (due to typos or renames) in the common case, and to make intentional uses explicit. The core problem is that reading from a non-existing property issues a diagnostic that makes the issue immediately apparent, while writing to a non-existing property is entirely silent. PHP gives no indication whatsoever that the programmer has made a mistake. |
A common counter-argument is that even if PHP itself does not detect the mistake, static analysis still can. While this is true to a degree, there are a number of problems: | A common counter-argument is that even if PHP itself does not detect the mistake, static analysis still can. While this is true to a degree, there are a number of problems: | ||
- | - Static analysis in IDEs (probably the most wide-spread | + | - Static analysis in IDEs (probably the most widespread |
- Static analysis can only analyze assignments with a known object type and property name. This does not include any kind of dynamic assignments, | - Static analysis can only analyze assignments with a known object type and property name. This does not include any kind of dynamic assignments, | ||
- | - On a more philosophical note, I believe that a programming language should be usable without external tooling. While IDE use is wide-spread | + | - On a more philosophical note, I believe that a programming language should be usable without external tooling. While IDE use is widespread |
Finally, if classes using dynamic properties are explicitly declared, then we no longer need to reserve space for them on each object. This would reduce the size of all objects (that don't opt-in to dynamic properties) by 8 bytes. However, this is a fairly long-term benefit that will require additional technical work to realize. | Finally, if classes using dynamic properties are explicitly declared, then we no longer need to reserve space for them on each object. This would reduce the size of all objects (that don't opt-in to dynamic properties) by 8 bytes. However, this is a fairly long-term benefit that will require additional technical work to realize. |
rfc/deprecate_dynamic_properties.txt · Last modified: 2021/11/26 13:59 by nikic