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 }
Comments
Post a Comment