Recently, I have been trying to object orient my PHP.
I understand OOP, but for some reason, I am having trouble when it comes to implementing it with Php.
I feel as though it isn't making sense. For instance, lets say I have a Friend class. It has many methods such as :
1) getName
2) getAge
3) sendMessage
etc..
When the user loads the webpage, I would populate an array of friend objects from the database. This would be all the users friends.
So far, it makes sense. But, let's say I make an ajax request to get information on a friend. The data is no longer available, correct?
This is where I am confused. I can't create the application thinking that I can always access these objects. So, how would this typically work?
Would it make sense not to store the friends as objects, and instead just have functions such as getFriend() or getFriendAge() which would take in the friendID and pull the data from the database?
I'm used to objects always existing, whereas in Php they only exist on the initial load of the webpage. My site uses lots of ajax.
I'm having difficulty putting this into words, hopefully my confusion will be cleared up. Thanks!