Anzeo Posted October 14, 2009 Share Posted October 14, 2009 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 Link to comment https://forums.phpfreaks.com/topic/177718-solved-accessing-methods-of-objects-in-an-array/ Share on other sites More sharing options...
ialsoagree Posted October 14, 2009 Share Posted October 14, 2009 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? Link to comment https://forums.phpfreaks.com/topic/177718-solved-accessing-methods-of-objects-in-an-array/#findComment-937073 Share on other sites More sharing options...
dymon Posted October 15, 2009 Share Posted October 15, 2009 It would be nice to specify the error you get, to get a hint where the problem comes from. Link to comment https://forums.phpfreaks.com/topic/177718-solved-accessing-methods-of-objects-in-an-array/#findComment-937283 Share on other sites More sharing options...
Anzeo Posted October 15, 2009 Author Share Posted October 15, 2009 Okay, apparently it does work like this :/ Sorry for your time! Link to comment https://forums.phpfreaks.com/topic/177718-solved-accessing-methods-of-objects-in-an-array/#findComment-937578 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.