严格的标准:My_Pdf_Document::save()的声明应该与Zend_Pdf::save的声明兼容


Strict Standards: Declaration of My_Pdf_Document::save() should be compatible with that of Zend_Pdf::save()

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

我正在实现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框架。

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

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

public function save(){

与Zend_Pdf中的签名相比:

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

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

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

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