【发布时间】:2014-04-18 19:01:10
【问题描述】:
我想知道是否可以创建一个函数并传递一个类名。然后该函数检查该类的实例当前是否存在,如果不存在,则创建该类的实例。此外,如果可能,使该变量成为全局变量并要求将其返回。我意识到返回可能是唯一的选择。
function ($class_name) {
// Check if Exists
// __autoload will automatically include the file
// If it does not create a variable where the say '$people = new people();'
$class_name = new $class_name();
// Then if possible make this variable a globally accessible var.
}
这可能还是我疯了?
【问题讨论】:
-
所以它假设创建一个空类,例如
class somename{}? -
不,自动加载包括文件和类。
-
所以如果该类存在,您要求创建该类的实例?
-
你确定你不只是想要singleton?
-
@case 你有没有解决这个问题?现在在javascript中遇到同样的问题。