#1
  1. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,195
    Rep Power
    601

    Object Reference Help


    I'm trying to do a little reverse engineering but I cannot seem to get the right syntax for the value I want. A var_dump($results) shows the following:
    Code:
    stdClass::__set_state(array(
       'row' =>
      array (
        'vproduct_id' => '54',
      ),
       'rows' =>
      array (
        0 =>
        array (
          'vproduct_id' => '54',
        ),
      ),
       'num_rows' => 1,
    ))
    I want to get the vproduct_id but this doesn't work:
    PHP Code:
    print($results->row[0]->vproduct_id); 
    I've not seen an object dumped quite this way before (stdClass::__set_state) so I would guess I need to do something less trivial to get that value. Can someone help? TIA.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  2. #2
  3. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    507
    Rep Power
    130
    That is an odd output.

    Try this, though:
    PHP Code:
    print $results->row['vproduct_id']; 
    The row element isn't an array, so row[0] isn't applicable.

    or:

    PHP Code:
    print $results->rows[0]['vproduct_id']; 
    rows[0] is shown as an array in the dump, not an object.
    LinkedIn: Dave Mittner
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    101
    Rep Power
    29
    That __set_state() magic method was a new one for me so I thought I'd dump a couple search results here.
    PHP doc: http://www.php.net/manual/en/languag...ject.set-state
    Some person's writeup: http://www.thoughtlabs.com/2008/02/0..._state-method/
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,195
    Rep Power
    601
    Thanks for the replies. Dave's suggestion was correct. I guess I was over-complicating it.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. Dark Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    15,690
    Rep Power
    9568
    That output is from var_export, not var_dump().

    I would expect
    PHP Code:
    $results->row->vproduct_id // or
    $results->row["vproduct_id"]

    $results->rows[0]->vproduct_id // or
    $results->rows[0]["vproduct_id"

IMN logo majestic logo threadwatch logo seochat tools logo