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

  • Home
  • SEARCH
  • 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 6591649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:27:07+00:00 2026-05-25T17:27:07+00:00

I have an object as this: object(stdClass)#27 (1) { [0] => object(stdClass)#26 (6) {

  • 0

I have an object as this:

object(stdClass)#27 (1)
{
    [0] => object(stdClass)#26 (6)
    {
        ["_id"] => object(MongoId)#24 (1)
        {
            ["$id"] => string(24) "4e6ea439caa47c2c0c000000" 
        }
        ["username"] => string(16) "wdfkewkghbrjkghb"
        ["email"]=> string(24) "wdhbfjkwhegerg@€rg.efg"
        ["password"]=> string(32) "4297f44b13955235245b2497399d7a93"
        ["slug"]=> string(16) "wdfkewkghbrjkghb"
        ["insert_datetime"]=> string(19) "2011-09-13 12:09:49" 
    } 

} 

I assign this object to $user.

I can’t get access on this object properties doing $user->username cause I receive the message:

Undefined property: stdClass::$username

Then if I do var_dump(get_object_vars($user)) it returns an empty array.

How do I grab the properties? I don’t want to use loops if I can avoid it.


The process is this:

  1. Retrieve results from mongo_db:

    $returns = array();
    
    while ($documents->hasNext())
    {
        if ($this->CI->config->item('mongo_return') == 'object')
        {
            $returns[] = (object) $documents->getNext();    
        }
    
        if ($this->CI->config->item('mongo_return') == 'array')
        {
            $returns[] = (array) $documents->getNext();
        }
    }
    
    if ($this->CI->config->item('mongo_return') == 'object')
    {
        return (object)$returns;
    }
    
    
    if ($this->CI->config->item('mongo_return') == 'array')
    {
        return $returns;
    }
    
  2. passing data to model

    function populateBy($what = false) {
        return $this->mongo_db
                    ->where($what)
                    ->get($this->tb['users']);
    }
    
  3. definitely grab results in controller:

    $what = array(
        'email'=>$email,
        'password'=>$password,
        'confirm'=>'1'
    );
    
    $user  = $this->model_user->populateBy($what);
    
  • 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-25T17:27:08+00:00Added an answer on May 25, 2026 at 5:27 pm

    As gilden says, the property you’re looking for is a property of a subobject. However, he missed that object property access is not the same as array element access.

    The real problem you’re facing here is that you’ve converted an array to object, and now you have a numeric property name. To get to properties you have to use syntax like $user->0->username, but clearly this is not valid as 0 is not a valid variable name.

    From the documentation:

    If an object is converted to an array, the result is an array whose
    elements are the object’s properties. The keys are the member variable
    names, with a few notable exceptions: integer properties are
    unaccessible
    [sic]; private variables have the class name prepended to the
    variable name; protected variables have a ‘*’ prepended to the
    variable name. These prepended values have null bytes on either side.
    This can result in some unexpected behaviour:

    The function get_object_vars converts back into an array again so that it appears to work, but in fact anything could happen: the behaviour is unspecified because the object elements were rendered inaccessible in the intermediate stage. Similarly, $user->{'0'}->username may work for you but I would avoid it.

    Unfortunately this means that you’ll have to change the way your code works: do not convert a numerically-indexed array to an object.

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

Sidebar

Related Questions

I have this object graph, I want to map: abstract Account (username, password, ...)
I have this object: class a { public string Application; public DateTime From, To;
I have an array like this (below is the var_dump) array 0 => object(stdClass)[11]
I have this object which is an instance of a superclass. I want to
I have an object (in this case a rating object from js-kit) that I
In my qt app I have this object, filled before setting up my QTreeWidget's
I have an object with a property called name. This object has a sub
I'm just wondering .. I have and object like this public class Entry{ public
We have lot of object with this kind of design : Interface and several
if I have an XML object like this: <a> <u date=2009-04-10 value=543/> <u date=2009-04-11

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.