Hi I have a simple code below that fetches, make, model and year from the database, but for some weird reason I get:
Fatal error: Cannot access protected property error, any ideas as to why this might be happening? (i btw have this code on a different server running with no issues.)

$count = 0;

foreach( $_product->getFitModels() as $fit ) {

    $trimmedData = ' '.$fit->row->make.' '.$fit->row->model.' '.$fit->row->year;

    $tempMMYArray[] = $trimmedData;     

}

Because you can only access protected properties and methods from the same class or a child class. If you want to access them from outside the class you need to make them public.

commented: thank you! +0

can you give me an example please?

I must be really tired.. lol.. of course, the property was protected, here is the fix:

class my_vehcile_row implements this_is_Configurable
{
    public $row;
 //etc 
 }

Glad you got it sorted :-)

because you can acesss it through the same class or child class .
this is the reason you are getting this error

SNIP

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.