-1

可能重复:
方法声明应与 PHP 中的父方法兼容

我正在实现从 SourceForge下载的 PDF (Zend_Pdf_Table)

现在的问题是它给了我以下错误。

 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 框架。

4

2 回答 2

3

您正在使用不同的签名(方法定义中的参数)覆盖这些方法。您不能覆盖 PHP 中的方法。

这是由 My_Pdf_Document 中的签名引起的:

public function save(){

与 Zend_Pdf 中的签名相比:

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

理想情况下,应该更新 My_Pdf_Document 签名以匹配 Zend_Pdf 签名。注意:这是一个严格错误,您可以关闭严格错误并忽略它,希望一切正常(但我强烈建议不要这样做)。

于 2012-03-19T12:37:52.103 回答
1

您尝试使用的库与 ZF 1.11 不完全兼容,而且该组件的作者似乎并未使用error_reporting(E_STRICT | E_ALL). 我对您的建议是下载该代码库,并error_reporting(E_STRICT | E_ALL)在适当的地方对其进行更正(正如其他人在此处指出的那样 - 有效地确保所有子方法签名与其父方法签名匹配)。

如果原作者仍在附近并希望保持更新,请将其提交给他们。

于 2012-03-19T17:49:57.090 回答