Welcome Guest, Not a member yet? Register   Sign In
Pass objects to array by value
#1

[eluser]obiron2[/eluser]
Guys,

I am writing my first fully OOP application; its a fantasy formula 1 league.

I have an object (PlayerTeam) which is a collection of objects (Driver 1, Driver 2, Chassis etc..)

Each object in the collection has a number of properties (name, points etc..)

I have a function which gets a list of all the teams and builds their profiles.

I have a function which gets the race results.

For each team I then loop through the race results and increment the points for each element of the team so that I know how many points Driver 1, Driver 2 and the car have scored.

I also want to build an array as part of the team object which is the individual race results for that team.

Code:
$team->Race->results[$Race->Venue] = $Race->Results.

but when I do this the result always displays the values from the last $Race; i.e. passed by reference

If I do

Code:
$team->Race->results[$Race->Venue] = $Race->Results->Driver1->RacePoints

Then the results are all different; i.e. passed by value.

Am I right in thinking that this is correct. If so, why does PHP treat these differently and how do I pass the object by value to the array.

Thanks in Advance.

Obiron


Messages In This Thread
Pass objects to array by value - by El Forum - 01-25-2008, 04:28 PM
Pass objects to array by value - by El Forum - 01-25-2008, 05:07 PM
Pass objects to array by value - by El Forum - 01-27-2008, 09:28 AM
Pass objects to array by value - by El Forum - 01-27-2008, 01:26 PM
Pass objects to array by value - by El Forum - 01-27-2008, 04:07 PM
Pass objects to array by value - by El Forum - 01-28-2008, 12:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB