title: Setting the key of an object property that is an array
body: <p>Just today I noticed a strange behavior in an object model that was previously working just fine (I have checked everything possible and nothing about its configuration has changed, so I am suspecting a change to PHP version and wondering if anyone else has experience anything similar)</p>
  
  <p>Until recently, I could set the keys of object properties that were arrays manually.  The specific implememation of this in one of my models was contained in a gallery class that looked like this:</p>
  
  <pre><code>public function __construct($gid){
          parent::__construct($gid);
          $this-&gt;Photos = $this-&gt;getPhotos();
          $this-&gt;AlbumCover = $this-&gt;getCover();
      }
  
      public function getPhotos(){
          $sql = 'SELECT GalleryPhotoID FROM GalleryPhoto WHERE GalleryID = ?';
          $params = array($this-&gt;GalleryID);
          $allids = DatabaseHandler::GetAll($sql, $params);
          $output = array();
          foreach($allids as $id){
              $gp = new GalleryPhoto($id['GalleryPhotoID']);
              $output[$gp-&gt;GalleryPhotoID] = $gp;
          }
          return $output;
      }
  </code></pre>
  
  <p>Irrelevant parts omitted.</p>
  
  <p>Basically, I could set the array keys of the Gallery's Photos object to the individual photo's id in the database.  This just made it easier to code for individual iteration and made the whole thing run smoother.</p>
  
  <p>Now, no matter what I set that key to, automatic integers are generated when the foreach runs.  I even tried typing a literal string in there, which theoretically should replace every iteration, but I still got incremented, automatic integers for the keys of the property Photos.</p>
  
  <pre><code>[Photos] =&gt; Array
          (
              [0] =&gt; GalleryPhoto Object
                  (
                      [GalleryID] =&gt; 9
                      [Caption] =&gt; 
                      [Orientation] =&gt; 0
                      [AlbumCover] =&gt; 
                      [DateAdded] =&gt; 2011-01-03 16:58:51
                      [GalleryPhotoID] =&gt; 63
                      [Thumbnail] =&gt; 
                      [Image] =&gt; 
                      [src] =&gt; http://..com/galleryImage/getImage/63
                  )
  
              [1] =&gt; GalleryPhoto Object
                  (
                      [GalleryID] =&gt; 9
                      [Caption] =&gt; 
                      [Orientation] =&gt; 0
                      [AlbumCover] =&gt; 
                      [DateAdded] =&gt; 2011-01-03 16:58:51
                      [GalleryPhotoID] =&gt; 64
                      [Thumbnail] =&gt; 
                      [Image] =&gt; 
                      [src] =&gt; http://..com/galleryImage/getImage/64
                  )
  
          )
  </code></pre>
  
  <p>Has the abillity to manually set keys within an object property that is an array been removed in some minor release and I am unaware of it?  I have googled all over, looked through the PHP manual site and found no answer.  Has anyone experienced anything similar?  Is there a better approach I should consider?  I only really went with this because it made it so much easier to implement a next/previous system via ajax requests back to the next logical id (keeping in mind that ids can be deleted between!)</p>
  
  <p>Thanks!</p>