uasort() Array was modified by the user comparison function
<p>I have a class that is basically a wrapper to an Array and implements IteratorAggregate.
When a new object of the class is created, it stores it's value in a protected variable called $value. The value can be a string, integer, etc.. or a traversable object (like an array).</p>

<p>This object is "recursive" since when a traversable object (like an array) is passed to the constructor, he creates another instance of the class. Here's the constructor to clarify:</p>

<pre><code>class ListItem implements \IteratorAggregate
{
    protected $readOnly = false;
    protected $key;
    protected $value;

    public function __construct($key, $value, $readOnly = false)
    {
        if($readOnly) $this-&gt;readOnly = true;
        if(is_numeric($key)) $key = 'index'.$key;
        $this-&gt;key = $key;

        if (is_array($value) || $value instanceof Traversable) {
            $this-&gt;value = array();
            foreach($value as $k =&gt; $v) {
                if(is_numeric($k)) $k = 'index'.$k;
                $this-&gt;value[$k] =  new ListItem($k, $v, $readOnly);
            }
        } else {
            $this-&gt;value = $value;
        }
    }

    public function __toString()
    {
        if ( is_array($this-&gt;value) ) {
            return 'ListItem OBJECT(' . count($this-&gt;value) . ')';
        } else {
            return $this-&gt;value;
        }
    }
</code></pre>

<hr>

<p>Right now, I'm trying to write a simple sorting method for the class.</p>

<p>To sort by Key, this works like a charm:</p>

<pre><code>$success = ksort($this-&gt;value, $comparison);
</code></pre>

<p>but to sort by value, asort does not work since the actual value I'm trying to sort is stored inside the value property.</p>

<p>So I tried using uasort, like this:</p>

<pre><code>   $success = uasort($this-&gt;value, function ($a, $b)
   {                    
      if ($a-&gt;value == $b-&gt;value) return 0;
      else if($a-&gt;value &lt; $b-&gt;value) return -1;
      else return 1;
   });
</code></pre>

<p>but for some unclear reason i get the following error:</p>

<blockquote>
  <p>Warning: uasort() [function.uasort]: Array was modified by the user
  comparison function in /* /* /* /ListItem.php on line 129</p>
</blockquote>

<hr>

<p><strong>Q. Why does this happen if I'm just accessing $value for comparison not actually changing anything?</strong></p>
