Fatal error: Call to undefined method PDF_reciept::FPDF() in C:\wamp\www\pdf\cr.php on line 8

Fatal error: Call to undefined method PDF_reciept::FPDF() in C:\wamp\www\pdf\cr.php on line 8

你能帮我看看这段代码吗....

<?php
    require('fpdf/fpdf.php');

    class PDF_reciept extends FPDF
    {
        function __construct($orientation = 'P', $unit = 'pt', $format = 'Letter', $margin = 40)
        {
            $this->FPDF($orientation, $unit, $format);
            $this->SetTopMargin($margin);
            $this->SetLeftMargin($margin);
            $this->SetRightMargin($margin);
            $this->SetAutoPageBreak(true, $margin);
        }

        function Header()
        {
            $this->SetFont('Arial', 'B', 20);
            $this->SetFillColor(36, 96, 84);
            $this->SetTextColor(225);
            $this->Cell(0, 30, "Nettuts+ Online Store", 0, 1, 'C', true);
        }

        function Footer()
        {
            $this->SetFont('Arial', '', 12);
            $this->SetTextColor(0);
            $this->XY(40, -60);
            $this->Cell(0, 20, "Thank you for shopping at Nettuts+", 'T', 0, 'C');
        }
    }

    $pdf = new PDF_reciept();

    $pdf->Output();
?>

错误Fatal error: Call to undefined method PDF_reciept::FPDF() in C:\wamp\www\pdf\cr.php on line 8
说你尝试访问 PDF_reciept::FPDF() 方法,但你的 class.

中没有这样的方法

您正在重写构造函数,因此您必须调用具有预期签名的父构造函数,例如 parent::__construct(); 在构造函数之上:

public function __construct($orientation = 'P', $unit = 'pt', $format = 'Letter', $margin = 40)
{
    parent::__construct($orientation, $unit, $format, $margin);
    //$this->FPDF($orientation, $unit, $format);
    $this->SetTopMargin($margin);
    $this->SetLeftMargin($margin);
    $this->SetRightMargin($margin);
    $this->SetAutoPageBreak(true, $margin);
}

此外,class 中的所有函数都应使用访问修饰符(public、私有等)声明

请检查您是否有 $this->FPDF($orientation, $unit, $format); fpdf/fpdf.php.

中定义的函数

或者如果你想调用父 FPDF 构造函数,那么使用 parent::__construct($orientation, $unit, $format, $margin);