Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3663864
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:34:44+00:00 2026-05-19T01:34:44+00:00

Just today I noticed a strange behavior in an object model that was previously

  • 0

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)

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:

public function __construct($gid){
        parent::__construct($gid);
        $this->Photos = $this->getPhotos();
        $this->AlbumCover = $this->getCover();
    }

    public function getPhotos(){
        $sql = 'SELECT GalleryPhotoID FROM GalleryPhoto WHERE GalleryID = ?';
        $params = array($this->GalleryID);
        $allids = DatabaseHandler::GetAll($sql, $params);
        $output = array();
        foreach($allids as $id){
            $gp = new GalleryPhoto($id['GalleryPhotoID']);
            $output[$gp->GalleryPhotoID] = $gp;
        }
        return $output;
    }

Irrelevant parts omitted.

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.

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.

[Photos] => Array
        (
            [0] => GalleryPhoto Object
                (
                    [GalleryID] => 9
                    [Caption] => 
                    [Orientation] => 0
                    [AlbumCover] => 
                    [DateAdded] => 2011-01-03 16:58:51
                    [GalleryPhotoID] => 63
                    [Thumbnail] => 
                    [Image] => 
                    [src] => http://..com/galleryImage/getImage/63
                )

            [1] => GalleryPhoto Object
                (
                    [GalleryID] => 9
                    [Caption] => 
                    [Orientation] => 0
                    [AlbumCover] => 
                    [DateAdded] => 2011-01-03 16:58:51
                    [GalleryPhotoID] => 64
                    [Thumbnail] => 
                    [Image] => 
                    [src] => http://..com/galleryImage/getImage/64
                )

        )

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!)

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:34:44+00:00Added an answer on May 19, 2026 at 1:34 am

    I don’t see anything wrong with what you have, and I’ve never experienced the behavior you describe. However, a quick solution could be to replace the assignment line with something like this:

    $output[$id['GalleryPhotoID']] = $gp;
    

    You could also echo $gp->GalleryPhotoID; to ensure that the GalleryPhotoID property can actually be accessed that way.

    Lastly, you said you replaced the above line with something akin to:

    $output['foobar'] = $gp;
    

    and it still created a new entry, with integer keys, for each entry? If that’s the case, then I think there may be something in the code you omitted that’s causing the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just had a strange problem show up with my XCode project. The project
I just started working with Android apps and was trying few sample programs. I
My java class (servlet) has been running fine, but recently, I noticed a problem.
We have several ASP.NET applications that use a sitemap which is populated via a
Just thought I'd share this in case anyone else has run into this. I
I've been having a play around with Mootools 1.3 server-side today. Its really nice
I was writing a query against a table today on a SQL Server 2000
I don't really know what I've just done so I'm just going to give
We are currently in the process of migrating from an aged proprietary directory service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.