Jump to content

[SOLVED] Accessing methods of objects in an array


Anzeo

Recommended Posts

Hi all,

 

 

 

I'll make it short:

 

I have an array of objects and the array is an attribute of another class. I want to acces functions of these objects, but the following code returns an error:

$this->array[1]->function()

 

Anyone knows how to do this correctly (I know a foreach is one way, but I'd prefer a variant of the above)?

 

TIA,

 

Anzeo

The code you have written implies that "array" is a property of a class, and the use of "$this" implies that you are inside that class. If this is wrong, then that's your problem.

 

If it is right, are you sure that array[1] has been defined as a new class?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.