Forum Moderators: coopster

Message Too Old, No Replies

Question about how Arrays, pointer and objects are handled

Question about array and object performance

         

jamesrandell

6:17 pm on Nov 18, 2008 (gmt 0)

10+ Year Member



Hi guys, got a question for you about arrays, pointers, objects and their performance.

Firstly i remember reading a PDF a while ago the explained the ins and outs of how arrays were handled inside PHP, and what happens to registrars and memory when an array is popped, pushed, copied and referenced. I can't for the life of me remember where i read this but if anyone has a clue of what I'm talking about i would be delighted if you could post a link!

Ok, the question. I have a registry class, a singleton that is instantiated once and used by all other classes. the registry has methods that allow add to, select and remove data to a property that is an array.

I have a second class, say "class A", that adds information to the registry.

Now i have another class: "class B", method that when a specific method is run it obtains information from the data property in the registry and processes it. This method requires information relating to a specific object that's created from class A.

My question is which is the better/right/correct/efficient way of doing this? should i:

a) Obtain a auto-incremental id of the data in the registry, and pass that id to class B, so the method looks in the registry to find the data?

b) Send the object to class B's method, so that it has immediate access to the data - and all other public properties?

c) something else more efficient?

It would be great to hear some insight on how PHP handles this stuff, and what would be the most memory efficient way of achieving this.

Thank you.

cameraman

5:32 pm on Nov 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If class B's method will be looking at the A object anyway, I would pass the object by reference to class B's method. I think I recall reading just recently that the optimizer will pass it by reference, but if you do it explicitly it removes all doubt.