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 6998337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:23:56+00:00 2026-05-27T20:23:56+00:00

In PHP is it considered good practise to store things like cookie or session

  • 0

In PHP is it considered good practise to store things like cookie or session information inside variables instead of callling them over and over. For example:

$happiness_level = $_SESSION['happiness_level'];

echo $happiness_level.' something';
echo $happiness_level.' something else';

vs:

echo $_SESSION['happiness_level'].' something';
echo $_SESSION['happiness_level'].' something else';

Is the 2nd one worse for performance. I ask because in jQuery it’s good performance practice to cache selectors by assigning them to variables so the DOM doesn’t have to be traversed each time the selector is called.

I was wondering if a similar rule applies in PHP. Or does PHP recognize internally that it already grabbed the session variable named “happiness_level” so the 2nd time it’s called, instead of doing all the extra work of looking up it’s value again, it instead just uses the original value from the 1st call?

Basically which is better (example 1 or 2) for performance, even if we’re talking milliseconds?

  • 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-27T20:23:57+00:00Added an answer on May 27, 2026 at 8:23 pm

    It is not the thing you should ever think of. Focus on application design

    Basically which is better (example 1 or 2) for performance, even if we’re talking milliseconds?

    Milliseconds hunting makes no sense in your case – just write the code you can effectively work with

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

Sidebar

Related Questions

I need to store a bunch of configuration information in PHP. I have considered
PHP stores its session information on the file system of the host of the
IS this bit of code in PHP/mysql considered a stored procedure? $sql = 'SELECT
I'm a PHP developer who is being considered for a job implementing IdeaBank ,
Currently, I only use stored procedures, is this considered good practice or bad? I
For my website i want to rewrite my url to: www.xxx.com/en/index.php instead of www.xxx.com/index.php?language=en
I'm looking for a good framework for PHP and see most offer the MVC
I was wondering if it's considered a bad practice to globally convert all PHP
PHP allows Unicode identifiers for variables, functions, classes and constants anyhow. It was certainly
Is htmlentities best solution to prevent XSS in PHP? Also I would like 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.