The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[SOLVED] Passing An Array Between Classes

This is a generic problem I'm having but an example is below. What I'm trying to do is get the data from the database (using model classes) and pass the data via an array to the view classes (via controller classes if any processing of the data needs to be done).

The example below works fine when dealing with the data in the model class but whatever I've tried so far either results in the display of only one line of the array or a line of the array still displays but it keeps on repeating until php times out.

I'm trying to keep the model classes solely for accessing and interfacing with the data with the controllers only processing the data and the views only displaying the data (with a minor bit of processing to decide what needs viewing).

I'm trying to always use while loops over foreach loops wherever possible due to the superior performance of while loops.

As i'm still relavtivly new to OOP php, my suspision is that i don't know the proper syntax for what i'm trying to do.

SilverBulletUK, you understand only part of the problem. The array is created fine in the model but when it is returned to the view (or whatever class has happened to call it), only one row of the array is returned.

Experimenting with foreach loops and while loops + print_r and var_dump has shown that the view will only ever receive one row of the array. Once i can get the whole array and not just one row to the view then i can remove all the display output from the model.

The foreach gives me one row at a time, the extract grabs the individual variables from the from then i display them, repeated until there are no more messages to list.

Result, all data display removed from the model, thanks for the help SirAdrian. SilverBulletUK, at the time i was experimenting with another view and model where i had exactly the same problem, now i can migrate the data viewing and processing to the view or controller as appropraite.