【问题标题】:Strict Standards: Declaration of My_Pdf_Document::save() should be compatible with that of Zend_Pdf::save() [duplicate]严格标准: My_Pdf_Document::save() 的声明应该与 Zend_Pdf::save() 的声明兼容 [重复]
【发布时间】:2012-04-03 22:41:32
【问题描述】:

可能重复:
Declaration of Methods should be Compatible with Parent Methods in 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 zend-framework pdf-generation zend-pdf


    【解决方案1】:

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

    这是由于 My_Pdf_Document 中的签名为:

    public function save(){
    

    与 Zend_Pdf 中的签名相比:

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

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

    【讨论】:

    • 那么我怎样才能去完成我想做的事呢?
    • 我已经编辑了有关该问题的更多详细信息。不过,解决方案的其余部分取决于您(除非其他人有更具体的帮助)。
    • 那我要改签名吗??
    • 只需更改您版本中的签名以匹配,并确保在您从您的版本调用父方法时将这些参数传递给父类。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-28
      • 2013-06-18
      • 2014-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多