Both sides previous revision
Previous revision
Next revision
|
Previous revision
Next revision
Both sides next revision
|
rfc:strict_operators [2020/07/06 14:48] jasny version 1.5 (doesn't affect switch) |
rfc:strict_operators [2020/07/06 15:14] jasny |
| |
* Version: 1.5 | * Version: 1.5 |
* Date: 2020-06-09 (first version: 2019-05-25) | * Date: 2020-07-06 (first version: 2019-05-25) |
* Author: Arnold Daniels, <jasny@php.net> | * Author: Arnold Daniels, <jasny@php.net> |
* Status: Under Discussion | * Status: Under Discussion |
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 is not based on the type of the other operand | * Type conversion is not based on the type of any of the operands |
* Type casting is not based on the value of any of the operands | * Type conversion is not based on the value of any of the operands |
* Operators will throw a ''%%TypeError%%'' for unsupported types | * Operators will throw a ''%%TypeError%%'' for unsupported types |
| |
In case an operator can work with several (or all) types, the operands need to match as no casting will be done by those operators. | In case an operator can work with several (or all) types, the operand types need to match as no type conversion will be done by those operators. |
| |
The one exception is that [[http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2|widening primitive conversion]] is allowed for ''%%int%%'' to ''%%float%%''. When doing a operation with an ''%%int%%'' and a ''%%float%%'', the ''%%int%%'' will silently casted to a ''%%float%%''. | The one exception is that [[http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2|widening primitive conversion]] is allowed for ''%%int%%'' to ''%%float%%''. When doing a operation with an ''%%int%%'' and a ''%%float%%'', the ''%%int%%'' will silently casted to a ''%%float%%''. |
| |
| Using ''strict_operators'' never changes the outcome of an operation. |
| |
===== Details for operands ===== | ===== Details for operands ===== |
===== FAQ ===== | ===== FAQ ===== |
| |
This RFC has a [[rfc/strict_operators/faq|FAQ]] that answers some questions | This RFC has an [[rfc/strict_operators/faq|FAQ]] that answers some questions |
| |
* [[rfc/strict_operators/faq#what_has_been_changed_since_the_initial_proposal|What has been changed since the initial proposal?]] | * [[rfc/strict_operators/faq#what_has_been_changed_since_the_initial_proposal|What has been changed since the initial proposal?]] |
* [[rfc/strict_operators/faq#are_built-in_functions_affected_by_strict_operators|Are built-in functions affected by strict_operators?]] | * [[rfc/strict_operators/faq#are_built-in_functions_affected_by_strict_operators|Are built-in functions affected by strict_operators?]] |
* [[rfc/strict_operators/faq#can_relational_operators_be_allowed_for_arrays|Can relational operators be allowed for arrays?]] | * [[rfc/strict_operators/faq#can_relational_operators_be_allowed_for_arrays|Can relational operators be allowed for arrays?]] |
| * [[rfc/strict_operators/faq#why_is_switch_not_affected|Why is switch not affected?]] |
* [[rfc/strict_operators/faq#are_there_cases_where_a_statement_doesn_t_throw_a_typeerror_but_yields_a_different_result|Are there cases where a statement doesn't throw a TypeError but yields a different result?]] | * [[rfc/strict_operators/faq#are_there_cases_where_a_statement_doesn_t_throw_a_typeerror_but_yields_a_different_result|Are there cases where a statement doesn't throw a TypeError but yields a different result?]] |
* [[rfc/strict_operators/faq#will_this_directive_disable_type_juggling_altogether|Will this directive disable type juggling altogether?]] | * [[rfc/strict_operators/faq#will_this_directive_disable_type_juggling_altogether|Will this directive disable type juggling altogether?]] |