-1

I have an array called $options. I want iterate through it's contents, so I do:

 foreach($options as $option){   
    print_r( $option);
 }

The resulting output gives me an object/array heffalump that starts like this...

Mage_Bundle_Model_Option Object
(
    [_defaultSelection:protected] => 
    [_eventPrefix:protected] => core_abstract
    [_eventObject:protected] => object
    [_resourceName:protected] => bundle/option
    [_isObjectNew:protected] => 
    [_data:protected] => Array
        (
            [option_id] => 20
            [parent_id] => 291

I want to reference values in _data, but I am stumped as to correct syntax to do this...

Abe
  • 298
  • 4
  • 12

2 Answers2

0

There's no syntax to access them from generic code. The Mage_Bundle_Model_Option class has declared its properties as protected, which means they can only be accessed from the class, its decendants, or its ancestors. You should use the class's public methods to make use of it, not access the properties directly.

Barmar
  • 741,623
  • 53
  • 500
  • 612
0

because the _data object is set as protected, it can only be accessed from inside the Mage_Bundle_Model_Option class or one that extends from it.

so what you would have to do is add a method inside Mage_Bundle_Model_Option along the lines of

function getData(){
 return $this->_data;
}

and then instead of your current foreach loop, do:

foreach($options->getData() as $option) {
   //do things
}
kero
  • 10,647
  • 5
  • 41
  • 51
Grantism
  • 374
  • 2
  • 3
  • 11