2012-03-19 20 views
-2

可能重複:
Declaration of Methods should be Compatible with Parent Methods in PHP嚴格的標準:My_Pdf_Document聲明::保存()應當與Zend_Pdf兼容::保存()

我實現PDF(Zend_Pdf_Table ),下載從SourceForge

現在的問題是,它給我下面的錯誤。

Error 1=Strict Standards: Declaration of My_Pdf_Document::save() should be compatible 
with that of Zend_Pdf::save() in D:\SVN data\WebClient_PHP\trunk\library 
\My\Pdf\Document.php on line 2 

2號線是

class My_Pdf_Document extends My_Pdf{ 

的第二個錯誤是

Error 2=Fatal error: Declaration of My_Pdf_Page::drawImage() must be compatible with 
that of Zend_Pdf_Canvas_Interface::drawImage() in D:\SVN data\WebClient_PHP\trunk 
\library\My\Pdf\Page.php on line 369 

一些代碼從我的行動

$instance = new abc(); 
$select  = $instance->Get_xyz($p); 

    try { 

    // create PDF 
     $pdf = new My_Pdf_Document('Call Logs Details.pdf', '.'); 

        // create page 
        $page = $pdf->createPage(); 

        // define font resource 
        $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); 

        // set font 
        $page->setFont($font, 24); 

        // create table 
        $table = new My_Pdf_Table(3); 

        // iterate over record set 
        // set up table content 
        while ($record = $select->fetch()) { 
        $row = new My_Pdf_Table_Row(); 
        $cols = array(); 
        foreach ($record as $k => $v) { 
         $col = new My_Pdf_Table_Column(); 
         $col->setText($v); 
         $cols[] = $col; 
        } 
        $row->setColumns($cols); 
        $row->setFont($font, 14); 
        $row->setBorder(My_Pdf::TOP, new Zend_Pdf_Style()); 
        $row->setBorder(My_Pdf::BOTTOM, new Zend_Pdf_Style()); 
        $row->setBorder(My_Pdf::LEFT, new Zend_Pdf_Style()); 
        $row->setCellPaddings(array(10,10,10,10)); 
        $table->addRow($row); 
        } 

        // add table to page 
        $page->addTable($table, 0, 0); 

        // add page to document 
        $pdf->addPage($page); 

        // save as file 
        $pdf->save(); 
        echo 'SUCCESS: Document saved!'; 
       } catch (Zend_Pdf_Exception $e) { 
        die ('PDF error: ' . $e->getMessage()); 
       } catch (Exception $e) { 
        die ('Application error: ' . $e->getMessage()); 
       } 

任何想法,爲什麼我收到以下錯誤。我在想什麼?我正在使用最新的Zend框架。

回答

3

您正在用不同的簽名(方法定義中的參數)重寫這些方法。你不能在PHP中重寫一個方法。

這是由簽名My_Pdf_Document所引起:

public function save(){ 

VS在Zend_Pdf人簽署:

public function save($filename, $updateOnly = false) 

理想的My_Pdf_Document簽名應進行更新,以匹配Zend_Pdf簽名。注意:這是嚴格的錯誤,您可以關閉嚴格的錯誤並忽略它,希望一切正常(但我強烈建議不要這樣做)。

+0

那麼我該如何去完成我想要做的事情? – 2012-03-19 12:39:54

+2

我已編輯了有關此問題的更多詳細信息。解決方案的其餘部分由您決定(除非其他人有更具體的幫助)。 – Paul 2012-03-19 12:54:13

+0

所以我應該改變簽名? – 2012-03-19 13:11:05

1

您正在嘗試使用的庫與ZF 1.11不完全兼容,並且該組件的作者未出現使用error_reporting(E_STRICT | E_ALL)的作者。我的建議是下載該代碼庫,在適當的地方更正error_reporting(E_STRICT | E_ALL)(如其他人在此注意到的 - 有效地確保所有子方法簽名都與其父母的方法簽名匹配)。

如果原始作者仍然在附近並且在意保持更新,請將其提交給他們。

相關問題