rfc:list_assoc_unique
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:list_assoc_unique [2022/12/01 14:24] – ilutov | rfc:list_assoc_unique [2022/12/01 18:19] (current) – Move to under discussion ilutov | ||
---|---|---|---|
Line 2: | Line 2: | ||
* Date: 2022-12-01 | * Date: 2022-12-01 | ||
* Author: Ilija Tovilo < | * Author: Ilija Tovilo < | ||
- | * Status: | + | * Status: |
* Proposed Version: PHP 8.3 | * Proposed Version: PHP 8.3 | ||
* Implementation: | * Implementation: | ||
Line 8: | Line 8: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | The < | + | The < |
definitions of equality and thus uniqueness. The most obvious one (i.e. < | definitions of equality and thus uniqueness. The most obvious one (i.e. < | ||
- | < | + | < |
This RFC proposes adding two new functions, < | This RFC proposes adding two new functions, < | ||
using strict equality (< | using strict equality (< | ||
- | <php> | + | <code php> |
List\unique([1, | List\unique([1, | ||
- | > [1, 2, 3, ' | + | // > [1, 2, 3, ' |
Assoc\unique([' | Assoc\unique([' | ||
- | > [' | + | // > [' |
- | </php> | + | </code> |
===== Proposal ===== | ===== Proposal ===== | ||
Line 41: | Line 41: | ||
Removing duplicates from arrays is a common use case provided by many programming languages. PHPs < | Removing duplicates from arrays is a common use case provided by many programming languages. PHPs < | ||
has been there for [[https:// | has been there for [[https:// | ||
- | However, PHP has multiple definitions of equality, four in particular supported by < | + | However, PHP has multiple definitions of equality, four in particular supported by < |
* < | * < | ||
Line 48: | Line 48: | ||
* < | * < | ||
- | Arguably, the most straight forward of those in terms of coercion is <php>SORT_STRING</ | + | Internally, <php>array_unique()</ |
- | options support arrays and objects, and all of them are subject to subtle coercion issues. Additionally, | + | scale badly. For this reason, the second parameter < |
- | lead to warnings that are likely undesirable, | + | < |
- | implementation detail. | + | |
+ | None of these options support arrays and objects, and other primitive types are subject to subtle coercion issues. | ||
+ | Additionally, | ||
+ | comparison is an implementation detail. | ||
==== Keys ==== | ==== Keys ==== | ||
Line 74: | Line 77: | ||
===== Alternative approaches ===== | ===== Alternative approaches ===== | ||
- | Previously, adding a new parameter | + | Previously, adding a new < |
- | people would prefer a new function over fixing the existing function | + | parameter |
- | to discover. | + | with a flag that might be more difficult to discover. |
===== Vote ===== | ===== Vote ===== |
rfc/list_assoc_unique.1669904651.txt.gz · Last modified: 2022/12/01 14:24 by ilutov