2016-03-07 93 views
0

兼容我找不到問題。此代碼可以工作多年,但在重置服務器之後,會顯示此致命錯誤。也許你可以幫助我。謝謝PHP致命錯誤:聲明...必須與

PHP Fatal error: Declaration of styBoxLoadEventArgs::__construct() must be compatible with EventArgs::__construct() in .../modules/sty/events/styBoxLoadEventArgs.php on line 4

代碼:

<?php 

class styBoxLoadEventArgs extends EventArgs 
{ 
    public $hide = false; 
    public $box; 

    public function __construct($box) 
    { 
     $this->box = $box; 
    } 
} 
?> 

這裏是EventArgs的

?php 

/** 
* EventArgs 
*/ 
abstract class EventArgs 
{ 

    public $sender, $senderClass, $senderObject, $event; 
    protected $items; 

    /** 
    * Creates new EventArgs object 
    */ 
    abstract public function __construct(); 

    /** 
    * Returns specified item 
    * 
    * @param string  item-name 
    * @return mixed 
    */ 
    public function __get($_name) 
    { 
     if(!array_key_exists($_name, $this->items)) 
     { 
      throw new BasicException("Item '" . $_name . "' not found"); 
     } 

     return $this->items[$_name]; 
    } 

    /** 
    * Sets specified item 
    * 
    * @param string  item-name 
    * @param mixed  value 
    */ 
    public function __set($_name, $_value) 
    { 
     if(!array_key_exists($_name, $this->items)) 
     { 
      throw new BasicException("Item '" . $_name . "' not found"); 
     } 

     $this->items[$_name] = $_value; 
    } 

    public function &GetByRef($_key) 
    { 
     if(!array_key_exists($_key, $this->items)) 
     { 
      throw new BasicException("Item '" . $_key . "' not found"); 
     } 

     return $this->items[$_key]; 
    } 

} 
+2

類'EventArgs'的構造函數是怎麼樣的? –

+0

擴展類時,構造方法必須與父類構造方法一致。我猜你的父類沒有參數或不同的參數? – purpleninja

+0

EventArgs被定義爲一個抽象類。我現在發佈代碼。也許你有一個想法。謝謝 – schnittstelle

回答

1

的代碼當一個孩子redeclares,父母已經定義的函數,你必須保持與該函數相同的提示/數據類型。假設EventArgs要求在其構造函數中使用特定的數據對象(或者在PHP7中使用嚴格的類型提示)。您的孩子還必須指定該數據類型。下面是一個例子(由一個向上)

class EventArgs 
{ 
    public function __construct(Array $box) 
    { 
     $this->box = $box; 
    } 
} 

在這種情況下,你的孩子構造函數也必須索要Array。有一些elaborate reasons for this

0

@schnittstelle,我認爲我們都在同一個軟件問題上工作。切換到PHP 5.6後,我的..date軟件不再使用。感謝這一頁,我現在更進一步,但又堅定不移。你和你一起跑過嗎?不幸的是,我是PHP的外行,在這裏看着我,但只需要幫助。也發佈在..date.de的論壇上,但沒有收到任何回覆。嗥。 LG Angelika

相關問題