views:

62

answers:

2

Hi, I have the following PHP object but I'm struggling to get the array item out of the object.

exampleBatch Object (
[file_path:protected] => 
[title:protected] => 
[description:protected] => 
[link:protected] => 
[items:protected] => Array ( ) 
[raw:protected] => data/example 
[feed_nid:protected] => 
Array ( 
    [0] => Array ( [path] => data/example/example/ [filename] => file.csv ) 
    [1] => Array ( [path] => data/example/example/ [filename] => file.csv ) 
    [2] => Array ( [path] => dexampleata/example// [filename] => file.csv ) ) 
[current_item:protected] => 
[created] => 0 
[updated] => 0 
[total:protected] => Array ( ) 
[progress:protected] => Array ( [fetching] => 1 [parsing] => 1 [processing] => 1 ) )

I need to access array containing the three keys and it's data for some post processing.

Whats the best way to go about grabbing the array?

+4  A: 

If you can edit the class, either change the property you care for to public or write a getter for it:

function getItems() {
    return $this->items ;
}

Otherwise if you can't edit the class itself, you can extend it since the properties you want are protected which means a child class can access them:

class YourClass extends ThatClass {

    public function getItems {
        //parent $items really
        return $this->items ;
    }

}

Then you'll need to create an instance of YourClass instead of ThatClass and get the items array from it.

Similarly for any other protected properties you want.

Fanis
Looking at the edited cleaned up code display, you are probably looking for `$this->progress` instead of `items`, but the same methods would apply.
Fanis
+2  A: 

The feed_nid property of your object is protected, so it cannot be accessed from outside the object.

Inside the object class, you should write a function like this:

function getFeedNid()
{
    return $this->feed_nid;
}

The original intent was obviously to keep that property internal and safe from external modification, so I would use this method instead of, for example, changing the protected $feed_nid declaration to public.

zombat