In fact, there is no right answer for this. Depending on how many users you load right away, how many text / blob fields are in your User table, whether your user table loads any related child objects. As aaronjensen says, this template is called lazy loading , and the opposite behavior (loading everything to the forefront if you need it) is called impatient loading .
However, there is a third option that you might want to consider, which is lazy loading the entire User object when accessing any of its properties:
public function get_email_address() { if (!$this->email_address) { $this->load_all_data_from_db($this->id) } return $this->email_address; }
The advantages of this approach are that you can create a collection of users (for example, a list of all users whose passwords are empty, maybe?) Only based on their identifiers, without a memory patch that completely loads each individual user, but then you only need one a database call for each user to fill in the remaining user fields.
source share