title: How to fix pass by reference in php after upgrading to 5.6.x
body: <p>I recently upgraded fom php 5.2 to 5.6 and there is some code I could not fix yet:</p>
  
  <pre><code>//Finds users with the same ip- or email-address
  function find_related_users($user_id) {
      global $pdo;
  
      //print_R($pdo);
  
      //Let SQL do the magic!
      $sth = $pdo-&gt;prepare('CALL find_related_users(?)');
      $sth-&gt;execute(array($user_id));
      //print_R($sth);
      //Contains references to all users by id, to check if a user has already been processed
      $users_by_id = array(); 
  
      //Contains arrays of references to users by depth
      $users_by_depth = array();
  
      while ($row = $sth-&gt;fetchObject()) {
          //Create array for current depth, if not present
          if (!isset($users_by_depth[$row-&gt;depth])) 
              $users_by_depth[$row-&gt;depth] = array();
  
          //If the user is new
          if (!isset($users_by_id[$row-&gt;id])) {
              //Create user array
              $user = array(
                  'id' =&gt; $row-&gt;id,
                  'name' =&gt; $row-&gt;name,
                  'email' =&gt; $row-&gt;email,
                  'depth' =&gt; $row-&gt;depth,
                  'adverts' =&gt; array()
              );
  
              //Add all users to depth array
              @array_push($users_by_depth[$row-&gt;depth], &amp;$user);
  
              //Add references to all users to id array (necessary to check if the id has already been processed)
              $users_by_id[$row-&gt;id] = &amp;$user;
          }
          //If user already exists
          else 
              $user = &amp;$users_by_id[$row-&gt;id];
  
          //Add advert to user
          if ($row-&gt;advert_id != null)
              array_push($user['adverts'], array(
                  'id' =&gt; $row-&gt;advert_id,
                  'title' =&gt; $row-&gt;advert_title,
                  'msgs' =&gt; $row-&gt;msgs,
                  'url' =&gt; $row-&gt;url
              ));
          #print_r($user);
          //Unset $user variable !!! 
          //If this is missing, all references in the array point to the same user
          unset($user);
      }
  
      //Return users, grouped by depth
      return $users_by_depth;
  }
  </code></pre>
  
  <p>If I simply remove the ampersand before the dollar sign, the function stops to work as intended. From other questions on stackoverflow I found that this is a call by reference and will brake for new php versions. However I could not find a solution yet.</p>
  
  <p>Thank you for any help on how to update this code for php 5.6.x</p>