php - Pass a class as parameter -


i trying pass class parameter not know if 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 accepting suggestions on other ways well.

i think looking string:

class user {     var $name; }  class userrepository {   private $type;   public function __construct($class) {                               ^^^^^^ string      $this->type = $class;   }    public function getinstance() {      return new $this->type;   } }  $obj = new userrepository('user');                           ^^^^^^ send string here  var_dump($obj->getinstance()); 

output:

object(user)#2 (1) { ["name"]=> null }

an example.


Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -