rfc:strict_operators
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
rfc:strict_operators [2020/07/06 11:48] jasny |
rfc:strict_operators [2020/07/15 14:27] jasny |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Strict operators directive ====== | ====== PHP RFC: Strict operators directive ====== | ||
- | * Version: 1.4 | + | * Version: 1.5 |
- | * Date: 2020-06-09 (first version: 2019-05-25) | + | * Date: 2020-07-06 (first version: 2019-05-25) |
* Author: Arnold Daniels, < | * Author: Arnold Daniels, < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 23: | Line 23: | ||
If strict_operators is enabled, the following stricter rules will be used; | If strict_operators is enabled, the following stricter rules will be used; | ||
- | * Operators may perform type casting, but not type juggling: | + | * Operators may perform type conversion, but not type juggling: |
- | * Type casting | + | * Type conversion |
- | * Type casting | + | * Type conversion |
* Operators will throw a '' | * Operators will throw a '' | ||
- | In case an operator can work with several (or all) types, the operands | + | In case an operator can work with several (or all) types, the operand types need to match as no type conversion |
The one exception is that [[http:// | The one exception is that [[http:// | ||
+ | |||
+ | Using '' | ||
===== Details for operands ===== | ===== Details for operands ===== | ||
Line 59: | Line 61: | ||
When used with a '' | When used with a '' | ||
+ | |||
+ | Custom compare handlers of objects (like '' | ||
==== String concatenation ==== | ==== String concatenation ==== | ||
Line 89: | Line 93: | ||
There a no changes to the ternary ('' | There a no changes to the ternary ('' | ||
- | |||
- | ===== Switch control structure ===== | ||
- | |||
- | The strict_operators directive may affect '' | ||
- | |||
- | The '' | ||
- | |||
- | <code php> | ||
- | function match($value) | ||
- | { | ||
- | switch ($value) { | ||
- | case [" | ||
- | return " | ||
- | break; | ||
- | case null: | ||
- | return " | ||
- | break; | ||
- | case 0: | ||
- | return " | ||
- | break; | ||
- | case " | ||
- | return " | ||
- | break; | ||
- | case " | ||
- | return " | ||
- | break; | ||
- | default: | ||
- | throw new Exception(" | ||
- | } | ||
- | } | ||
- | |||
- | match([" | ||
- | match(0); | ||
- | match(" | ||
- | match(" | ||
- | </ | ||
===== Motivating examples ===== | ===== Motivating examples ===== | ||
Line 152: | Line 120: | ||
This can lead to issues when numeric comparison is not expected, for example between two hexidecimal values. The hexidecimal value is instead interpreted as number with scientific notation. | This can lead to issues when numeric comparison is not expected, for example between two hexidecimal values. The hexidecimal value is instead interpreted as number with scientific notation. | ||
- | < | + | < |
$red = ' | $red = ' | ||
$purple = ' | $purple = ' | ||
Line 185: | Line 153: | ||
$a < $b; // true | $a < $b; // true | ||
</ | </ | ||
- | |||
- | The logic of relational operators other than '' | ||
==== Strict vs non-strict comparison of arrays ==== | ==== Strict vs non-strict comparison of arrays ==== | ||
Line 197: | Line 163: | ||
To compare the values of two arrays in a strict way while not concerned about the order, requires ordering the array by key prior to comparison. | To compare the values of two arrays in a strict way while not concerned about the order, requires ordering the array by key prior to comparison. | ||
- | |||
- | ==== Switch control structure ==== | ||
- | |||
- | The '' | ||
- | |||
- | <code php> | ||
- | function match($value) | ||
- | { | ||
- | switch ($value) { | ||
- | case 2: | ||
- | return " | ||
- | break; | ||
- | case 1: | ||
- | return " | ||
- | break; | ||
- | case 0: | ||
- | return " | ||
- | break; | ||
- | default: | ||
- | throw new Exception(" | ||
- | } | ||
- | } | ||
- | |||
- | match(" | ||
- | </ | ||
==== Inconsistent behavior ==== | ==== Inconsistent behavior ==== | ||
Line 243: | Line 184: | ||
This is proposed for PHP 8.0. | This is proposed for PHP 8.0. | ||
- | |||
- | ===== FAQ ===== | ||
- | |||
- | [[rfc/ | ||
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
Line 254: | Line 191: | ||
* Does not affect any functionality concerning explicit typecasting. | * Does not affect any functionality concerning explicit typecasting. | ||
* Is largely unaffected by other proposals like [[rfc/ | * Is largely unaffected by other proposals like [[rfc/ | ||
+ | |||
+ | ===== FAQ ===== | ||
+ | |||
+ | This RFC has an [[rfc/ | ||
+ | |||
+ | * [[rfc/ | ||
+ | * [[rfc/ | ||
+ | * [[rfc/ | ||
+ | * [[rfc/ | ||
+ | * [[rfc/ | ||
+ | * [[rfc/ | ||
+ | * [[rfc/ | ||
+ | * [[rfc/ | ||
+ | * [[rfc/ | ||
+ | * [[rfc/ | ||
+ | * [[rfc/ | ||
+ | * [[rfc/ | ||
+ | * [[rfc/ | ||
+ | * [[rfc/ | ||
===== Implementation ===== | ===== Implementation ===== | ||
- | [[https:// | + | https:// |
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
Primary vote: Accept the RFC and merge the patch? Yes/No. Requires a 2/3 majority. | Primary vote: Accept the RFC and merge the patch? Yes/No. Requires a 2/3 majority. | ||
- | |||
- | Secondary vote: Should strict_operators affect the switch statement? Yes/No Requires a 50%+1 majority. | ||
rfc/strict_operators.txt · Last modified: 2020/07/15 14:27 by jasny