I have two code examples below. One works, but the second (using extend to create a new class wrapper) doesn’t.
Note, I’ve greatly simplified the following examples.
Approach #1
page.php:
<?php
include("fpdf.php");
$pdf = new FPDF;
$pdf->AddPage();
$pdf->SetFont('Arial','',11);
$pdf->Output();
?>
This works as expected. It creates a blank page.
Approach #2
But then, using the FPDF by inheritance, I get an error (see below the code blocks).
myPDF.php:
<?php
require ("fpdf.php");
class myPDF extends FPDF {
function createMyPage() {
$this->AddPage();
$this->SetFont('Arial','',11);
$this->Output();
}
}
?>
page.php:
<?php
include("myPDF.php");
$pdf = new myPDF;
$pdf->createMyPage();
?>
This second approach produces the following PHP warning and FPDF error:
Warning: in_array() expects parameter 2 to be array, null given in /var/www/fpdftest/fpdf.php on line 526 FPDF error: Undefined font: helvetica
Any ideas what I’m missing here?
When you create your wrapper class, be sure to call the parent constructor:
http://fpdf.org/en/tutorial/tuto6.htm