rfc:typed_properties_v2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
rfc:typed_properties_v2 [2019/01/07 14:48]
nikic Add errata: inc/dec overflow
rfc:typed_properties_v2 [2019/01/10 19:00]
nikic typos
Line 1299: Line 1299:
 ==== Incrementing/decrementing beyond the maximal/minimal value ==== ==== Incrementing/decrementing beyond the maximal/minimal value ====
  
-When a value is incremented beyond ''PHP_INT_MAX'' or decremented beyond ''PHP_INT_MIN'' it is converted into a floating-point value and incremented/decremented as a floating-point value. Additionally, under PHPs type verification rules (both strict //and// weak), assigning an out-of-range floating point value to an integer is illegal.+When a value is incremented beyond ''PHP_INT_MAX'' or decremented beyond ''PHP_INT_MIN'' it is converted into a floating-point value and incremented/decremented as a floating-point value. Additionally, under PHP'type verification rules (both strict //and// weak), assigning an out-of-range floating point value to an integer is illegal.
  
-As stated, this would result in the following peculiar behavior: Incrementing an ''int'' property past the maximal valuewould always be an error, because ''(float)PHP_INT_MAX + 1'' exceeds the integer range. However, decrementing an ''int'' property past the minimal value would only error on 32-bit systems. The reason is that on 64-bit systems ''(float)PHP_INT_MIN - 1'' is the same as ''(float)PHP_INT_MIN'', which is accurately representable as a double-precision floating point number and as such can be assigned back to an ''int'' property without error.+As stated, this would result in the following peculiar behavior: Incrementing an ''int'' property past the maximal value would always be an error, because ''(float)PHP_INT_MAX + 1'' exceeds the integer range. However, decrementing an ''int'' property past the minimal value would only error on 32-bit systems. The reason is that on 64-bit systems ''(float)PHP_INT_MIN - 1'' is the same as ''(float)PHP_INT_MIN'', which is accurately representable as a double-precision floating point number and as such can be assigned back to an ''int'' property without error.
  
 As such, we would always generate an error on increment/decrement overflow, apart from the case of decrements on 64-bit systems. As such, we would always generate an error on increment/decrement overflow, apart from the case of decrements on 64-bit systems.
  
-To avoid this, we instead define that incrementing/decrementing an ''int'' property past the maximal/minimal value always generated an error. It should be noted that this only affects the ''++'' and ''--'' operators. Overflows caused by other means are not handled specially.+To avoid this, we instead define that incrementing/decrementing an ''int'' property past the maximal/minimal value always generates an error. It should be noted that this only affects the ''++'' and ''%%--%%'' operators. Overflows caused by other means are not handled specially.
  
 ===== Changelog ===== ===== Changelog =====
rfc/typed_properties_v2.txt · Last modified: 2019/01/11 16:16 by nikic