Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 53185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:01:26+00:00 2026-05-10T17:01:26+00:00

What should happen when I call $user->get_email_address() ? Option 1: Pull the email address

  • 0

What should happen when I call $user->get_email_address()?

Option 1: Pull the email address from the database on demand

public function get_email_address() {     if (!$this->email_address) {         $this->read_from_database('email_address');     }     return $this->email_address; } 

Option 2: Pull the email address (and the other User attributes) from the database on object creation

public function __construct(..., $id = 0) {     if ($id) {         $this->load_all_data_from_db($id);     } }  public function get_email_address() {     return $this->email_address; } 

My basic question is whether it’s best to minimize the number of database queries, or whether it’s best to minimize the amount of data that gets transferred from the database.

Another possibility is that it’s best to load the attributes that you’ll need the most / contain the least data at object creation and everything else on demand.

A follow-up question: What do ORM abstraction frameworks like Activerecord do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:01:26+00:00Added an answer on May 10, 2026 at 5:01 pm

    There really isn’t a correct answer for this. Depends on how many users you’re loading at once, how many text/blob fields are in your User table, whether your user table loads any associated child objects. As aaronjensen says, this pattern is called lazy loading – and the opposite behaviour (loading everything up front just in case you need it) is known as eager loading.

    That said, there is a third option you might want to consider, which is lazy-loading the entire User object when any of its properties are accessed:

    public function get_email_address() {     if (!$this->email_address) {         $this->load_all_data_from_db($this->id)     }     return $this->email_address; } 

    Advantages of this approach are that you can create a collection of users (e.g. a list of all users whose passwords are blank, maybe?) based on their IDs only, without the memory hit of fully loading every single user, but then you only require a single database call for each user to populate the rest of the user fields.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't seem to get this working, what should happen is when the user
Here is what I want to happen: The user should click a link/button that
I'm trying to understand when I should call Query.close(Object) or Query.closeAll(); From the docs
I have 2 functions from separate scripts that communicate. What should happen is, if
How can WCF client detect that server requires security certificate? The detection should happen
Should functions that act on and object, say to fill it out from xml,
Before I begin, I should tell you that this only happens in iOS 5.1.
I have a feeling that this should really not be all that difficult, yet
I call my JavaScript function. Why do I sometimes get the error 'myFunction is
What the program should do: After the user clicks the delete button with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.