rfc:non_coercing_array_keys_in_strict_mode

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:non_coercing_array_keys_in_strict_mode [2017/07/27 22:30] – created wesnetmorfc:non_coercing_array_keys_in_strict_mode [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 8: Line 8:
 ===== Proposal ===== ===== Proposal =====
  
-This RFC proposes to emit a strict standards deprecation notice when PHP would coerce array keys' types (e.g. float to int), in case the page is declared using ''strict_types''.+This RFC proposes to emit a strict-standards deprecation notice when PHP would coerce array keys' types (e.g. float to int), in case the page uses ''strict_types = 1''.
  
 For example: For example:
Line 15: Line 15:
 <?php declare(strict_types = 1); <?php declare(strict_types = 1);
 $array = []; $array = [];
-$array[42.42] = 123; // Deprecated / Strict Standards: invalid key float(42.42), assuming int(42)+$array[42.42] = 123; 
 +// 7.3+ Deprecated / Strict Standards: invalid key float(42.42), assuming int(42) 
 +// 8.0+ TypeError invalid array key type "float", expecting int or string
 </code> </code>
  
Line 22: Line 24:
  
 ===== Impact on generics ===== ===== Impact on generics =====
-This proposal is friends with generics, as this change won't directly influence future decisions about generics.+This proposal is friends with generics, as this change won't directly influence future decisions about them.
  
 For example, arrays could be declared as ''Array<KT, CT> where KT is mixed and CT is mixed'' thus allowing any key type to be used. For example, arrays could be declared as ''Array<KT, CT> where KT is mixed and CT is mixed'' thus allowing any key type to be used.
  
-However in non-strict, people will continue to rely on coercion of keys, so when type arguments are not specified, the array "constructors" should continue to default to ''<int|string, mixed>''.+However in non-strict, people will continue to rely on coercion of keys, so when type arguments are not specified, the array "constructors" could continue to default to ''<int|string, mixed>''.
  
 <code php> <code php>
rfc/non_coercing_array_keys_in_strict_mode.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1