rfc:structs-v2
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:structs-v2 [2024/04/23 16:26] – ilutov | rfc:structs-v2 [2024/04/24 20:33] (current) – ilutov | ||
---|---|---|---|
Line 276: | Line 276: | ||
Only mutating methods can and must be called using the '' | Only mutating methods can and must be called using the '' | ||
+ | |||
+ | Similarly, classes trying to implement '' | ||
TOOD: Check if we can enforce '' | TOOD: Check if we can enforce '' | ||
Line 337: | Line 339: | ||
TODO: This is actually broken currently. | TODO: This is actually broken currently. | ||
- | This modification is //not// considered mutating, because the object may change from some other place anyway. Structs behave closer to objects, so interior mutation is not allowed. | + | This modification is //not// considered mutating, because the object may change from some other place anyway. Structs behave closer to arrays, so interior mutation is not allowed. |
<code php> | <code php> | ||
Line 350: | Line 352: | ||
<code php> | <code php> | ||
$bigNum1 = new BigNum(1); | $bigNum1 = new BigNum(1); | ||
- | $bigNum2 = new BigNum(1); | + | $bigNum2 = $bigNum1; |
$reflection = new ReflectionProperty(BigNum:: | $reflection = new ReflectionProperty(BigNum:: | ||
- | $reflection-> | + | $reflection-> |
+ | |||
+ | // Desired behavior | ||
+ | var_dump($bigNum1, | ||
</ | </ | ||
- | To work properly, '' | + | for this to work properly, '' |
For this reason, I have opted to throw when passing a struct object to '' | For this reason, I have opted to throw when passing a struct object to '' | ||
Line 363: | Line 368: | ||
Inheritance is currently not allowed for structs. Structs are mainly targeted at data modelling, which should prefer composition over inheritance. There are currently no known technical issues with inheritance for structs, but we may want to be cautious when introducing them, and carefully consider the plethora of subtle semantic nuances. | Inheritance is currently not allowed for structs. Structs are mainly targeted at data modelling, which should prefer composition over inheritance. There are currently no known technical issues with inheritance for structs, but we may want to be cautious when introducing them, and carefully consider the plethora of subtle semantic nuances. | ||
+ | |||
+ | Implementing interfaces is allowed, however. Interface methods may be '' | ||
===== Hashing ===== | ===== Hashing ===== | ||
Line 390: | Line 397: | ||
$moved = $value; | $moved = $value; | ||
$value = null; | $value = null; | ||
- | return $value; | + | return $moved; |
} | } | ||
Line 403: | Line 410: | ||
===== Performance ===== | ===== Performance ===== | ||
- | Because '' | + | Assignment to a property now needs to check whether |
===== Backwards incompatible changes ===== | ===== Backwards incompatible changes ===== | ||
- | '' | + | '' |
+ | |||
+ | There are no other backwards incompatible changes. | ||
===== Vote ===== | ===== Vote ===== |
rfc/structs-v2.1713889607.txt.gz · Last modified: 2024/04/23 16:26 by ilutov