2013-09-29 21 views
1

我知道OOPS以下類型的構造函數:有多少類型的構造是有在PHP

  • 參數
  • 默認
  • 複製

,但我不知道是否PHP支持所有這些。什麼是在PHP的支持

+0

爲什麼不試試自己? –

+0

我試過複製,沒有任何解決方法不起作用。簡單地說,我需要一些關於它是否確認我是否缺少東西:) – Arihant

+1

檢查此http://php.net/manual/en/language.oop5.cloning.php複製構造函數 –

回答

1

PHP支持所有這些構造函數的類型:

class A { 
    // default is a build-in non-parametrized one 

    public function __construct(/* arguments */){ 
     // parametrized 
    } 

    public function __clone(){ 
     // copy 
    } 
} 

// if __construct() is not declared, then uses default one: 
$a = new A; 

// if __construct() is declared, then uses parametrized one: 
$a = new A(/* arguments */); 

// if __clone() is declared, then uses copy one: 
$b = clone $a; 

參考文獻:

  1. Constructors and Destructors
  2. Object cloning
相關問題