====== PHP RFC: Coercing array keys in strict mode deprecation ====== * Version: 0.1 * Date: 2017-07-27 * Authors: Wes (Twitter@WesNetmo) * Status: Draft * First Published at: https://wiki.php.net/rfc/non_coercing_array_keys_in_strict_mode ===== 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 uses ''strict_types = 1''. For example: Except the emitted notice, code will continue to behave as it does currently, until the notice is removed and replaced with a ''TypeError'' in PHP 8.0. If the RFC is accepted, the removal version is binding, but an RFC to block the removal could be used if considered necessary. ===== Impact on 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 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" could continue to default to ''''. $array = [22.22 => 123, "foo" => "bar"]; $array = array(22.22 => 123, "foo" => "bar"); // will be equivalent (at least in non-strict mode) to: $array = [22.22 => 123, "foo" => "bar"]; $array = array(22.22 => 123, "foo" => "bar"); If non-strict users desire it, in future this can be changed so that type arguments would default to '''' instead. This would have the effect of eliminating the coercion also in non-strict mode, unless code is changed to explicitly define the type arguments (i.e. from ''[]'' to '''', which would bring the coercion back). ===== Backward Incompatible Changes ===== None ===== Proposed PHP Version(s) ===== PHP 7.3 ===== Open Issues ===== N/A ===== Voting ===== 2/3 majority required ===== Patches and Tests ===== N/A ===== References ===== Discussion: [[http://google.com]]