rfc:arithmetic_operator_type_checks

Differences

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

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
rfc:arithmetic_operator_type_checks [2020/04/01 13:54] – created nikicrfc:arithmetic_operator_type_checks [2020/04/02 09:55] – Fix "WTF?" example output. salathe
Line 1: Line 1:
 ====== PHP RFC: Stricter type checks for arithmetic/bitwise operators ====== ====== PHP RFC: Stricter type checks for arithmetic/bitwise operators ======
-  * Date: 2020-04-01+  * Date: 2020-04-02
   * Author: Nikita Popov <nikic@php.net>   * Author: Nikita Popov <nikic@php.net>
-  * Status: Draft+  * Status: Under Discussion
   * Target Version: PHP 8.0   * Target Version: PHP 8.0
   * Implementation: https://github.com/php/php-src/pull/5331   * Implementation: https://github.com/php/php-src/pull/5331
Line 14: Line 14:
 <PHP> <PHP>
 var_dump([] % [42]); var_dump([] % [42]);
-// int(1)+// int(0)
 // WTF? // WTF?
 </PHP> </PHP>
Line 61: Line 61:
  
 The changes proposed here are intended to be entirely uncontroversial. The changes proposed here are intended to be entirely uncontroversial.
 +
 +===== Open Questions =====
 +
 +It might be worthwhile to go one step further:
 +
 +  * Make non-numeric string operands throwing. Non-numeric here means not starting with a digit (optionally preceded by whitespace). This would not apply to operators that have special behavior for strings, such as string increment.
 +  * Make overflowing float values throwing for operators that expect an integer (''%'', ''%%<<%%'', ''%%>>%%'', ''&'', ''|'', ''^'').
 +
 +This would have the advantage of aligning the semantics with parameter type checks in coercive mode, for the types ''int'' and ''int|float'' depending on operator. The only discrepancy would be in the handling of ''null'', which is already not as strictly enforced.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
rfc/arithmetic_operator_type_checks.txt · Last modified: 2020/05/05 14:12 by nikic