Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 基于变量创建对象的新实例_Php_Variables - Fatal编程技术网

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

我试图创建一个对象的实例,但对象类名是手工设置的

在config.php中:

define('DIRECTORY', 'RaptorDirectory');
在类文件中:

$this->directory = new DIRECTORY; // <--- how do I use the constant there?

$this->directory=新目录;// 这里不能使用常量,但可以使用变量,例如

$class = DIRECTORY;
$this->directory = new $class;

谢谢我想我会切换到一个变量。这有记录吗?@davidosomething