title: The different behavior of the function uasort in PHP 5.5 and PHP 7.0
body: <p>I encountered a strange behavior of Magento 1.8 after changing php version from 5.5 to 7.0. 
  This strange behavior is due to a change in the work function <code>uasort</code>.</p>
  
  <p>Source code:</p>
  
  <pre><code>&lt;?php
  
  $arr = [
      "nominal" =&gt; [
          "before" =&gt; ["subtotal", "grand_total"],
          "after" =&gt; [],
          "_code" =&gt; "nominal"
      ],
      "subtotal" =&gt; [
          "after" =&gt; ["nominal"],
          "before" =&gt; ["grand_total", "shipping", "freeshipping", "tax_subtotal", "discount", "tax", "weee"],
          "_code" =&gt; "subtotal"
      ],
      "shipping" =&gt; [
          "after" =&gt; ["subtotal", "freeshipping", "tax_subtotal", "nominal", "weee"],
          "before" =&gt; ["grand_total", "discount", "tax_shipping", "tax"],
          "_code" =&gt; "shipping"
      ],
      "grand_total" =&gt; [
          "after" =&gt; ["subtotal", "nominal", "shipping", "freeshipping", "tax_subtotal", "discount", "tax"],
          "before" =&gt; [],
          "_code" =&gt; "grand_total"
      ],
      "msrp" =&gt; [
          "before" =&gt; [],
          "after" =&gt; [],
          "_code" =&gt; "msrp"
      ],
      "freeshipping" =&gt; [
          "after" =&gt; ["subtotal", "nominal"],
          "before" =&gt; ["tax_subtotal", "shipping", "grand_total", "tax", "discount"],
          "_code" =&gt; "freeshipping"
      ],
      "discount" =&gt; [
          "after" =&gt; ["subtotal", "shipping", "nominal", "freeshipping", "tax_subtotal", "tax_shipping", "weee"],
          "before" =&gt; ["grand_total", "tax"],
          "_code" =&gt; "discount"
      ],
      "tax_subtotal" =&gt; [
          "after" =&gt; ["0" =&gt; "freeshipping", "1" =&gt; "subtotal", "3" =&gt; "nominal"],
          "before" =&gt; ["tax", "discount", "shipping", "grand_total", "tax_shipping", "weee"],
          "_code" =&gt; "tax_subtotal"
      ],
      "tax_shipping" =&gt; [
          "after" =&gt; ["shipping", "tax_subtotal", "subtotal", "freeshipping", "nominal"],
          "before" =&gt; ["tax", "discount", "grand_total"],
          "_code" =&gt; "tax_shipping"
      ],
      "tax" =&gt; [
          "after" =&gt; ["subtotal", "shipping", "discount", "tax_subtotal", "freeshipping", "tax_shipping", "nominal", "weee"],
          "before" =&gt; ["grand_total"],
          "_code" =&gt; "tax"
      ],
      "weee" =&gt; [
          "after" =&gt; ["subtotal", "tax_subtotal", "nominal", "freeshipping"],
          "before" =&gt; ["shipping", "tax", "discount", "grand_total", "tax_shipping"],
          "_code" =&gt; "weee"
      ]
  ];
  
  
  function _compareTotals($a, $b)
  {
      $aCode = $a['_code'];
      $bCode = $b['_code'];
      if (in_array($aCode, $b['after']) || in_array($bCode, $a['before'])) {
          $res = -1;
      } elseif (in_array($bCode, $a['after']) || in_array($aCode, $b['before'])) {
          $res = 1;
      } else {
          $res = 0;
      }
      echo sprintf("%s &lt;&gt; %s: %s", $aCode, $bCode, $res) . "\n";
      return $res;
  }
  
  uasort($arr, '_compareTotals');
  var_dump(array_keys($arr));
  </code></pre>
  
  <p>In php 5.5 result is:</p>
  
  <pre><code>freeshipping &lt;&gt; subtotal: 1
  freeshipping &lt;&gt; shipping: -1
  weee &lt;&gt; freeshipping: 1
  tax &lt;&gt; freeshipping: 1
  tax_shipping &lt;&gt; freeshipping: 1
  tax_subtotal &lt;&gt; freeshipping: 1
  discount &lt;&gt; freeshipping: 1
  nominal &lt;&gt; freeshipping: -1
  freeshipping &lt;&gt; grand_total: -1
  msrp &lt;&gt; freeshipping: 0
  subtotal &lt;&gt; msrp: 0
  nominal &lt;&gt; subtotal: -1
  tax_subtotal &lt;&gt; shipping: -1
  weee &lt;&gt; tax_subtotal: 1
  tax &lt;&gt; tax_subtotal: 1
  tax_shipping &lt;&gt; tax_subtotal: 1
  grand_total &lt;&gt; tax_subtotal: 1
  discount &lt;&gt; tax_subtotal: 1
  shipping &lt;&gt; tax_subtotal: 1
  grand_total &lt;&gt; discount: 1
  grand_total &lt;&gt; shipping: 1
  grand_total &lt;&gt; tax_shipping: 1
  grand_total &lt;&gt; tax: 1
  weee &lt;&gt; grand_total: -1
  shipping &lt;&gt; discount: -1
  tax &lt;&gt; shipping: 1
  tax_shipping &lt;&gt; shipping: 1
  weee &lt;&gt; shipping: -1
  tax_shipping &lt;&gt; discount: -1
  tax &lt;&gt; tax_shipping: 1
  discount &lt;&gt; tax_shipping: 1
  tax &lt;&gt; discount: 1
  
  array(11) {
    [0] =&gt;
    string(7) "nominal"
    [1] =&gt;
    string(8) "subtotal"
    [2] =&gt;
    string(4) "msrp"
    [3] =&gt;
    string(12) "freeshipping"
    [4] =&gt;
    string(12) "tax_subtotal"
    [5] =&gt;
    string(4) "weee"
    [6] =&gt;
    string(8) "shipping"
    [7] =&gt;
    string(12) "tax_shipping"
    [8] =&gt;
    string(8) "discount"
    [9] =&gt;
    string(3) "tax"
    [10] =&gt;
    string(11) "grand_total"
  }
  </code></pre>
  
  <p>In php 7.0 result is:</p>
  
  <pre><code>nominal &lt;&gt; subtotal: -1
  subtotal &lt;&gt; shipping: -1
  shipping &lt;&gt; grand_total: -1
  grand_total &lt;&gt; msrp: 0
  msrp &lt;&gt; freeshipping: 0
  freeshipping &lt;&gt; discount: -1
  discount &lt;&gt; tax_subtotal: 1
  msrp &lt;&gt; tax_subtotal: 0
  freeshipping &lt;&gt; tax_subtotal: -1
  discount &lt;&gt; tax_shipping: 1
  freeshipping &lt;&gt; tax_shipping: -1
  tax_subtotal &lt;&gt; tax_shipping: -1
  discount &lt;&gt; tax: -1
  tax &lt;&gt; weee: 1
  tax_shipping &lt;&gt; weee: 1
  freeshipping &lt;&gt; weee: -1
  tax_subtotal &lt;&gt; weee: -1
  
  array(11) {
    [0] =&gt;
    string(7) "nominal"
    [1] =&gt;
    string(8) "subtotal"
    [2] =&gt;
    string(8) "shipping"
    [3] =&gt;
    string(11) "grand_total"
    [4] =&gt;
    string(4) "msrp"
    [5] =&gt;
    string(12) "freeshipping"
    [6] =&gt;
    string(12) "tax_subtotal"
    [7] =&gt;
    string(4) "weee"
    [8] =&gt;
    string(12) "tax_shipping"
    [9] =&gt;
    string(8) "discount"
    [10] =&gt;
    string(3) "tax"
  }
  </code></pre>
  
  <p>In PHP5 <code>grand_total</code> is the last element, but in PHP7 - no.
  The problem is related to the uncertainty of the location <code>msrp</code> element. I found a <a href="https://stackoverflow.com/questions/9194281/sort-algorithm-magento-checkout-totals-sorted-wrongly-causing-wrong-shipping-ta">research</a> on this subject associated with php 5.</p>
  
  <p>I solved this problem by indicating a relative position <code>msrp</code>. But I wonder why it works in php5 and does not work in php7. These are the features of the new version of php or a bug?</p>
  
  <p><strong>addition #1</strong></p>
  
  <p>The problem not only in that the PHP7 don't knows how to sort equal elements, for example <code>msrp</code> and <code>grand_total</code>.
  If you look at item <code>shipping</code> and <code>freeshipping</code>, then they are clearly defined, who should be earlier. PHP5 solves this problem, and PHP7 not.</p>