Php 基于变量创建对象的新实例
我试图创建一个对象的实例,但对象类名是手工设置的 在config.php中:Php 基于变量创建对象的新实例,php,variables,Php,Variables,我试图创建一个对象的实例,但对象类名是手工设置的 在config.php中: define('DIRECTORY', 'RaptorDirectory'); 在类文件中: $this->directory = new DIRECTORY; // <--- how do I use the constant there? $this->directory=新目录;// 这里不能使用常量,但可以使用变量,例如 $class = DIRECTORY; $this->directo
define('DIRECTORY', 'RaptorDirectory');
在类文件中:
$this->directory = new DIRECTORY; // <--- how do I use the constant there?
$this->directory=新目录;// 这里不能使用常量,但可以使用变量,例如
$class = DIRECTORY;
$this->directory = new $class;
谢谢我想我会切换到一个变量。这有记录吗?@davidosomething