By business model or business objects, I mean simple old objects, such as "User" with all their property names, address, ...; in addition to all user properties, it can be said that each user will have an “AppointmentBook” object, each book has a set of “TimeSlot” objects, etc. There are objects in the business model with links between them, at least the way I code the business model in Java. The question arises:
To initialize my business objects, in Java , I would
- retrieve all data from the database only once during application initialization,
- map data from my database to my business objects.
- save in memory (cards) and they will be available for all requests.
PHP Share-Nothing-Architecture confuses me for proper OO programming: If I use the same logic, I will have to extract all the objects from the database for each request (I know that I can still cache, but you don’t cache all of my DB, this is not a question about caching, but rather about the way of programming in PHP and its architecture).
So, let's say that for one HTTP request, I just need the User properties, and I do not need to access its destination book. It would be useless to retrieve all the data from the database for all the objects that the user refers to, since I just need its properties. This means that I will initialize PHP objects from my model with a large number of NULL values (NULL due to objects contained in User, which I will not load), which can subsequently lead to errors.
I was wondering how professional PHP developers typically use their business objects. (I come with Java)
UPDATE: It was foolish to say that I would load the entire database into memory while running the application in Java. What I prefer is that if I need to get a specific user, I can just download all of his data and this will be available through all the requests.
source share