views:

43

answers:

1

stdClass::__set_state(array(
   'zone1' => 
  array (
    0 => 
    stdClass::__set_state(array(
       'id' => '123',
       'owner' => '234',
       ...
    )),

Hi,

My basics are a bit shot, so I'm having trouble with this... I need to create the above structure, but I'm not sure how to...

+5  A: 
$a = new stdclass;
$a->zone1 = array();
$a->zone1[0] = new stdclass;
$a->zone1[0]->id = "123";
$a->zone1[0]->owner = "234";

Alternatively, relying upon the fact that arrays are converted to stdClass objects when casted into objects:

$a = (object) array(
    "zone1" => array(
       (object) array("id" => "123", "owner" => "234"),
    ),
);

For this, var_export gives:

stdClass::__set_state(array(
   'zone1' => 
  array (
    0 => 
    stdClass::__set_state(array(
       'id' => '123',
       'owner' => '234',
    )),
  ),
))

Note that, has Daniel has pointed out, stdClass doesn't actually have a __set_state method. I supposed you were just exemplifying the structure of the variable by giving the output of var_export. Serialization should be done with serialize instead.

Artefacto