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

  • Home
  • SEARCH
  • 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 6800373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:57:40+00:00 2026-05-26T18:57:40+00:00

Lets say I’m storing an array or object called $_SESSION[logged_in_user] . If I need

  • 0

Lets say I’m storing an array or object called $_SESSION["logged_in_user"].

If I need to refer to it repeatedly throughout the script, which of the following is the “best practice”?

  • Use $_SESSION["logged_in_user"] each time (i.e. $_SESSION["logged_in_user"]["first_name"])?

  • Copy the object into a new variable like $logged_in = $_SESSION["logged_in_user"]?

  • Create a reference to the session variable like $logged_in =& $_SESSION["logged_in_user"]

I’m probably overthinking this, but my main concerns are script overhead and readability. I’m not sure if referring to a session variable repeatedly is slower than referring to an inline-declared variable. I also don’t know if copying a session variable into a “regular” variable adds more overhead than is necessary. I do like the readability of $logged_in["first_name"] over $_SESSION["logged_in_user"]["first_name"].

So is there a best practice here, or does it really not matter?

  • 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. Editorial Team
    Editorial Team
    2026-05-26T18:57:41+00:00Added an answer on May 26, 2026 at 6:57 pm

    You’re not overthinking it…. thinking is good!

    I personally use symfony 1.4 to code in, which solves problems like these, but you may choose to stay lean 🙂

    I’d think OO (object oriented). Create a user class. Then make calls like UserFactory::getCurrentUser() or User::getCurrentUser() which will return the currently logged in user object. Among the member variables of that class would be the user_id. However, you’ll be able to add addition functionality and data to that class.

    Remember, thinking in OO means using abstract terms that are very close to the problem domain. User, Car, Order, etc. You don’t have to be specific and you don’t have to include all available information in that class for it to be “complete”, whatever that is. Only include the data that you need at the time (keep yagni in mind). The classes are illusions of the concrete, real-world things. Just as 3D modelling is an illusion of a real world thing.

    Hope that helps…

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

Sidebar

Related Questions

Lets say I have a single object of type Car which I want to
Lets say I have object Tom which has class Person. Class Person String Name
Lets say I have a Dictionary object: Dictionary myDictionary<int, SomeObject> = new Dictionary<string, SomeObject>();
Lets say I have an array like this: string [] Filelist = ... I
Lets say you need to attach some JavaScript functionality to an ASP.NET User Control
Lets say I have heap allocated A* , which I want to pass as
Lets say we have a program which contains such classes: public interface AbstractItem {
Lets say my file lives in the config folder and it's called config/foo.yml .
Lets say that I need to execute this query with EF in business layer
Lets say I have an array of javascript objects, and I am trying to

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.