Php 使用类成员作为类名访问静态成员
我知道这是一种非常罕见的情况,但我想使用一个类属性来保存我的类名,然后通过该属性访问它的静态成员。以下是我想要的示例:Php 使用类成员作为类名访问静态成员,php,class,properties,static,classname,Php,Class,Properties,Static,Classname,我知道这是一种非常罕见的情况,但我想使用一个类属性来保存我的类名,然后通过该属性访问它的静态成员。以下是我想要的示例: class a{ private $className = "User"; public function list(){ $this->className::model()->findAll(); // error occurs here! // equal to // User::mode
class a{
private $className = "User";
public function list(){
$this->className::model()->findAll(); // error occurs here!
// equal to
// User::model()->findAll();
}
}
到目前为止,我已经尝试了各种可能性,唯一有效的方法是使用范围变量。尝试使用:
$class = $this->className;
$class::model()->findAll();
不幸的是,我已经知道了,我正在寻找一种方法来做到这一点,没有范围变量你也可以像这样使用call\u user\u func:call\u user\u func数组$this->className,'model'->findAll;