views:

45

answers:

1

Okay. Now I give up. I have been playing with this for hours.

  • I have a variable name $data.
  • The variable contains these contents: (extracted by using var_export())

    array (
      'headers' =>
      array (
        'content-type' => 'multipart/alternative; boundary="_689e1a7d-7a0a-442a-bd6c-a1fb1dc2993e_"',
      ),
      'ctype_parameters' => 
      array (
        'boundary' => '_689e1a7d-7a0a-442a-bd6c-a1fb1dc2993e_',
      ),
      'parts' => 
      array (
        0 => 
        stdClass::__set_state(array(
          'headers' => 
          array (
            'content-type' => 'text/plain; charset="iso-8859-1"',
            'content-transfer-encoding' => 'quoted-printable',
          ),
          'ctype_primary' => 'text',
        )),
      ),
    )
    

    I removed some non-essential data.

  • I want to access the headers value (on the second line above) - simple: $data->headers
  • I want to access the headers value (on the fourteenth line after the stdClass:: stuff) - how?

How can I possibly access the values within the stdClass::__set_state section?

I tried var_export($data->parts); but all I get is

NULL

+3  A: 

Is this variable declared the way you posted it? Like:

$data = array(
          'headers' =>
             array (
             …

In that case, I'm not quite sure how you can access 'headers' via $data->headers. It should be $data['headers'], because it is an array, not an object.

Further down, stdClass::__set_state(array('headers' => …)) statically calls the method __set_state of the class stdClass. Whatever this method does I don't know, but only its return value will be assigned to the 'parts' => array(0 => ...) key.

If OTOH what you're showing is the result of var_dump($data), then this is incorrect nonsense, since stdClass::__set_state() would never show up in a var_dump. Something is fishy either in your code or in what you posted and it's hard to say without seeing more of it.

Disregard the above, var_export prints classes this funky way.

$data['headers'] should do it for the first headers part. Further down, $data['parts'][0]->headers should do the trick.

deceze
First off, `var_export` _not_ `var_dump`. Secondly, the data is not declared, I'm getting it from a third party library. Thirdly, I am confused :(
George Edison
Good news! I just noticed that you were right - I am accessing the data as `$data->member` instead of `$data['member']` - silly me! That helped me solve the problem. +1 and best answer for you!
George Edison
I didn't know classes where printed this way by `var_export`. Learned something. :)
deceze