PHP类问题
class Gdn {
const AliasDispatcher = 'Dispatcher';
protected static $_Factory = NULL;
public static function Dispatcher() {
$Result = self::Factory(self::AliasDispatcher);
return $Result;
}
public static function Factory($Alias = FALSE) {
if ($Alias === FALSE)
return self::$_Factory;
// Get the arguments to pass to the factory.
//$Args = array($Arg1, $Arg2, $Arg3, $Arg4, $Arg5);
$Args = func_get_args();
array_shift($Args);
return self::$_Factory->Factory($Alias, $Args);
}
}
如果我像 $Dispatcher = Gdn::Dispatcher(); 这样调用 Dispatcher(),返回 self::$_Factory->Factory($Alias, $Args);< /代码> 是什么意思?
class Gdn {
const AliasDispatcher = 'Dispatcher';
protected static $_Factory = NULL;
public static function Dispatcher() {
$Result = self::Factory(self::AliasDispatcher);
return $Result;
}
public static function Factory($Alias = FALSE) {
if ($Alias === FALSE)
return self::$_Factory;
// Get the arguments to pass to the factory.
//$Args = array($Arg1, $Arg2, $Arg3, $Arg4, $Arg5);
$Args = func_get_args();
array_shift($Args);
return self::$_Factory->Factory($Alias, $Args);
}
}
If I call the Dispatcher() like $Dispatcher = Gdn::Dispatcher();
, what does return self::$_Factory->Factory($Alias, $Args);
mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这意味着 Dispatcher() 返回一个对象,并且该对象是 Factory() 创建的对象的副本。
It means Dispatcher() is returning an object, and that object is a copy of something created by Factory().
self:: 表示您正在引用当前对象的类
由于工厂是一个递归函数,它将不断调用自身,直到用完参数,然后返回当前工厂类中设置的工厂。
如果你愿意:
“blah->Factory('test1','test2',test3','test4')” 它的运行方式如下:
我不知道为什么你会想要它,但这就是它的作用
self:: means you are refering to the class of the current object
since factory is a recursive function it will keep calling itself until it runs out of arguments and then returns the factory that is set in the current factory class.
if you would do:
"blah->Factory('test1','test2',test3','test4')" it would run like:
i dont know WHY you would want it, but this is what it does