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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:34:34+00:00 2026-05-23T11:34:34+00:00

I have created a user class that has information about the user. Also, I

  • 0

I have created a user class that has information about the user. Also, I have extended that class with another class called LoggedInUser.

The point of LoggedInUser is to be able to easily tell if the user is authenticated and logged in by simply checking for the existence of the LoggedInUser object like this:

class User {
 //properties
}

class LoggedInUser extends User {
 //some additional token stuff
}

$isLoggedIn = new LoggedInUser();

class Router {
 public function gotoRoute() {
  if($isLoggedIn) {
   // perform the action
  }
 }
}

As far as I can tell, $isLoggedIn is not accessible to the class, so should I pass it into the constructor? or is there a better way to do all of this?

  • 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-23T11:34:35+00:00Added an answer on May 23, 2026 at 11:34 am

    In my opinion you have two options. You can pass the LoggedInUser into the Router::__construct(). Or you can create the LoggedInUser in the Router::__construct()

    1st option:

    $LoggedInUser = new LoggedInUser();
    $Router = new Router($LoggedInUser);
    

    2nd option

    $Router = new Router();
    
    // in router class file
    __construct() {
        $this->YourProperty = new LoggedInUser();
    }
    

    I like the 1st option. It is called Dependency Injection

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

Sidebar

Related Questions

I have created a user control (CheckedDirTree) that exposes a CheckedFolder property which in
I have created an application that uses settings.settings to store some user specific settings
I have created an application that runs in the taskbar. When a user clicks
I have an entity model that has audit information on every table (50+ tables)
I have a member profiles application that stores simple information about members of a
I'm creating a Network class that has a many-to-one relationship with the Django User
I have created a user control to handle adding comments to certain business entities,
I have created a user login page and am using Forms Authentication. Users are
I have created one user named tuser with create database rights in SQL server
I have created a COM enabled .NET User Control and am wondering what is

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.