2010-10-19 56 views
0
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()如$Dispatcher = Gdn::Dispatcher();return self::$_Factory->Factory($Alias, $Args);是什麼意思?PHP類問題

回答

0

self ::表示您正在引用當前對象的類 ,因爲factory是一個遞歸函數,它將繼續調用自身,直到它耗盡參數,然後返回在當前工廠類中設置的工廠。

,如果你會做: 「blah->廠( '測試1', '測試2',TEST3' , 'TEST4')」,將運行像:

blah->factory('test1','test2','test3','test4') 
    blah->$_Factory->Factory('test1',array('test2','test3','test4')) 
     blah->$_Factory->Factory(array('test2','test3','test4')); 
      blah->$_Factory->Factory(); 
      // oh hey, i dont have any arguments, replace it with my default argument 'false' and thus return the factory 
      return self::$_Factory; 

我不知道你爲什麼會想要它,但這是它的作用

1

這意味着Dispatcher()正在返回一個對象,並且該對象是由Factory()創建的東西的副本。

+0

我不明白靜態變量後的箭頭,所以Gdn :: $ _ Factory是一個對象嗎? – nzh 2010-10-19 14:56:30