samouray
samouray

Reputation: 578

FPDF - How to fix the "Fatal error: Call to undefined method PDF::FPDF()" Using Write_html

I am using this script http://fpdf.org/en/script/script50.php and I am getting the error:

Fatal error: Call to undefined method PDF::FPDF() in MyPath/html_table.php on line 55

it is this call to FPDF that is throwing the exception :

$this->FPDF($orientation,$unit,$format);

I don't understand why, knowing that the pdf class extends FPDF and I have the fpdf.php file in the same directory as the html_table.php file, is there any way to fix this error? Thank you

Upvotes: 0

Views: 12310

Answers (2)

AltShiftZero
AltShiftZero

Reputation: 363

I can't find $this->FPDF anywhere in the script you shared. When you extend a class, the extended class is in the $this of the class you extended it with. The constructor of the extended class will always be ran when you create a new instance of this class unless you define a constructor yourself, which you did in the PDF-class as the script you shared shows. If you want to run the constructor of the class you extended, you should do this from within the contructor of the extending class using parent::__construct(); which tells PHP that it should at that moment run the contructor of the parent class (the extended class). This is already the case in the script you shared:

    //Call parent constructor
    parent::__construct($orientation,$unit,$format);

So when you run new PDF() it will call the contructor of the PDF-class, which will call the constructor of FPDF. When you call the constructor again as mentioned in your answer by using the $this->__construct($orientation,$unit,$format); line, this will result in the PDF-contructor to be called twice.

Upvotes: 0

samouray
samouray

Reputation: 578

Fixed it.

I actually needed to replace :

$this->FPDF($orientation,$unit,$format);

by:

$this->__construct($orientation,$unit,$format);

The original script has this error, so for anyone wanting to use the script don't forget to fix this error first. Good luck.

Upvotes: 5

Related Questions