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 - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -