2

I have a activerecord model which has an array in it of say: "$sessions". What I would like to do is make this a 2d array so as to be indexed in the following way:

["0"=>Session(Object), "1"=>Session(Object)]

Now to add cream on top I would like to make it so the user could do:

user->sessions[1]->id = "ghgh"

And the __get would understand whether there is an object already in that position in the class variable ("$sessions") and add/edit the property to the class or it will make a new class in that position called "Session".

I am a bit confused how I could get PHP (if possible) to get a __get on an index of an array.

hakre
  • 193,403
  • 52
  • 435
  • 836
Sammaye
  • 43,242
  • 7
  • 104
  • 146
  • I think I may have found my answer just now lol. By settings the object to a class implementing the arrayaccess interface I cna actually scroll through the array as an array and assign a new class to indexes which are none existant and edit object which do exist: http://stackoverflow.com/questions/5939677/set-get-with-array-properties – Sammaye Jul 23 '11 at 12:25

1 Answers1

1

I think you're looking for ArrayAccess.

Interface to provide accessing objects as arrays.

adlawson
  • 6,303
  • 1
  • 35
  • 46
  • Yes I believe so :) I will follow that answer I postede as a comment thanks for the strengthing of my idea :) – Sammaye Jul 23 '11 at 12:52