检查另一个类中的类实例

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?

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

I'm not completely sure if this is what you are after but what about making the $isLoggedIn a private variable so that classes can check its existence?

private $isLoggedIn = new LoggedInUser();

First of all, variables are always locale to a class. You cannot assign a variable outside of a class and then call it.

In a simple script like this, that's what I would do:

class Router {
    public function gotoRoute() {
        $isLoggedIn = $isLoggedIn = new LoggedInUser();
        if( $isLoggedIn instanceof User ) {
        // perform the action
        }
    }
}