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

The Archive Base Latest Questions

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

I have many session vars. Should I use this $_SESSION[SessionHelper::ROUTING] = SessionHelper::MODULE_A; class SessionHelper

  • 0

I have many session vars. Should I use this

$_SESSION[SessionHelper::ROUTING] = SessionHelper::MODULE_A;

class SessionHelper {
   const ROUTING = 'SessionHelper.routing';
   const MODULE_A = 1;
   const MODULE_B = 2;
}

or this?

$_SESSION['routing'] = 1;

The first seems to be maintenanable but hard to read in some case. For example:

if(isset($_SESSION[SessionHelper::ROUTING]) && 
   $_SESSION[SessionHelper::ROUTING] = SessionHelper::MODULE_A) {
....

The second is quite short but if there is a change, we must change everywhere the “routing” exist. Further more, it can pollute the session scope because the ‘routing’ string is so common.

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

    If you really need a session helper (say: if you really need a class abstracting a PHP session), then use the $_SESSION superglobal only inside that class (and not outside). So you have the superglobal encapsulated and you can replace it with test-doubles.

    Next to that, this depends on the use of the session store. I bet it’s highly dynamic, so I don’t see much value in specifying array keys as constants first w/o any futher use (e.g. valid/invalid key checks aren’t done).

    I hope this does not sound harsh, because it’s not meant so. Please ask if something is unclear or you have further questions. As jprofitt wrote in his answer, preventing magic numbers is something very useful, but I’m not totally convinced, that you actually introduce them here or if it isn’t just dynamic properties (especially if you create a session store class).

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

Sidebar

Related Questions

hi i have many session values in my project and i use the syntext
We have many projects that use a common base of shared components (dlls). Currently
I have many sites that use the same root category of the Main Site.
Mysql begin generate big IO. One website have many rows in session,requests table (
I have faced this question in my Interview as well. I do have many
Stumped on this one. I have a many to many self referencing relationship(FluentNH) mapped
I am using .net 1.1. I have a session class in which I have
I have this below code(this is a sample, there are many more other conditions
I have read many posts on Session-scoped data in MVC, but I am still
I have in many places in my ASP.NET project used the Session variable for

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.