Skip to content
  • totten's avatar
    Disambiguate `Address.state_province_id:abbr` (PHP asort) · 1353ce0f
    totten authored
    Consider `ContactJoinTest::testCreateWithPrimaryAndBilling` which writes the value:
    
      'address_billing.state_province_id:abbr' => 'AK',
    
    The symbol 'AK' can map to three places: Akwa Ibom (Nigeria), Atakora
    (Benin), and Alaska (USA).  This is an ambiguous choice.  It should be
    resolved in a consistent way.
    
    One flavor of ambiguity comes from PHP.  After fetching from MySQL, there is
    a secondary sorting (via `CRM_Utils_Array::asort()` => `asort()`).  Per
    https://www.php.net/asort, the outcome is quirky:
    
    > If two members compare as equal, they retain their original order.  Prior
    > to PHP 8.0.0, their relative order in the sorted array was undefined.
    
    On PHP 7, you cannot resolve this with any of the standard sort methods
    (`asort`, `usort`, `ksort`, etc). They all have the same issue.
    
    However...  the docs for `\Collator::asort()` indicate no such issue.
    Switching to `\Collator::asort()` causes the tests to pass on PHP 7.3.  And
    we already use `\Collator::asort()`.
    1353ce0f