-1

Possible Duplicate:
Declaration of Methods should be Compatible with Parent Methods in PHP

I am implementing PDF (Zend_Pdf_Table), downloaded from SourceForge

now the problem is that its giving me following errors.

 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

Line#2 is

class My_Pdf_Document extends My_Pdf{

the second error is

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

some code from my action

  $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());
                }

Any idea why i am getting following errors.What i am missing ?? i am using latest Zend framework.

Community
  • 1
  • 1
Shreya Ghoshal
  • 79
  • 2
  • 14

2 Answers2

3

You are overriding those methods with a different signature (the parameters in the method definition). You cannot override a method in PHP.

This is caused by the signature in My_Pdf_Document being:

public function save(){

vs the signature in Zend_Pdf being:

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

Ideally the My_Pdf_Document signature should be updated to match the Zend_Pdf signature. Note: This is a Strict error, you could turn off strict errors and ignore it, hoping that everything worked (but I would strongly recommend against doing that).

Paul
  • 6,572
  • 2
  • 39
  • 51
1

The library you are attempting to use is not completely compatible with ZF 1.11, also, it does not appear the author of that component was using error_reporting(E_STRICT | E_ALL). My suggestion to you is to download that codebase, correct it for error_reporting(E_STRICT | E_ALL) where appropriate (as others have noted here - effectively, make sure all the child method signature match their parents method signature).

If the original author is still around and cares for keeping it updated, commit it back to them.