将类作为参数传递

I am trying to pass a class as a parameter but I do not know if it is possible.

class User {
    var $name;
}

class UserRepository {
  private $type;
  public function __construct(Class) {
     $this->type = Class;
  }

  public function getInstance() {
     return new $this->type;
  }
}

$obj = new UserRepository(User);

I am accepting suggestions on other ways to do it as well.

I think you are just looking for a string:

class User {
    var $name;
}

class UserRepository {
  private $type;
  public function __construct($Class) {
                              ^^^^^^ this will be a string
     $this->type = $Class;
  }

  public function getInstance() {
     return new $this->type;
  }
}

$obj = new UserRepository('User');
                          ^^^^^^ send a string here

var_dump($obj->getInstance());

output:

object(User)#2 (1) { ["name"]=> NULL }

An example.

Just instantiate the class and call that

$user = new User();
$obj = new UserRepository($user);

Another option (since User contains only variables) is to make the variable static and use that

class User {
    public static $name;
}
$obj = new UserRepository(User::$name);