扩展PHP类不接受变量

时间:2009-08-18 18:59:26

标签: php

我正在扩展FPDF并希望包含一些外部变量,但它不起作用。我做错了什么?

<?php

class PDF extends FPDF {

    public var $DocNum; 
    public var $cliente;
    public var $noCliente; 
    public var $noTienda;
    public var $noPedido;

    function Header() {
        $this->Image('fpdf/cabMCR.jpg',5,10,100,0,'JPG','');

        $this->SetFont('Arial','B','16');
        $this->SetXY(125,15);
        $this->Write(5,'FACTURA');

        // doing some more stuff here
    }

    function Footer() {
        $this->SetTextColor(150,150,150);
        $this->SetXY(10,285);
        $this->SetFont('Helvetica','I',7);
        $this->Write (5, 'MCR Electronic S.L. Inscrita en el Registro Mercantil de Madrid en Tomo 15819, folio 163, Seccion 8ª, hoja M-267058, CIF: B82766452');
        $this->SetTextColor(0,0,0);
    }
}

$pdf=new PDF();

$pdf->Open();
$pdf->AddPage('P');
$pdf->SetDisplayMode(real,'default'); 
$pdf->SetAuthor('Company S.L');
$pdf->SetTitle('Factura MCR');

$pdf->$DocNum = $DocNum;
$pdf->$cliente = $cliente;
$pdf->$noCliente = $noCliente; 
$pdf->$noTienda = $noTienda;
$pdf->$noPedido = $noPedido;

?>

2 个答案:

答案 0 :(得分:3)

除非你用变量做一些奇怪的事情,否则你不想用$引用类成员。

而不是:

$pdf->DocNum = $DocNum;
$pdf->$cliente = $cliente;
$pdf->$noCliente = $noCliente; 
$pdf->$noTienda = $noTienda;
$pdf->$noPedido = $noPedido;    

应该更像这样:

$pdf->DocNum    = 'somevalue';
$pdf->cliente   = 'somevalue';
$pdf->noCliente = 'somevalue';
$pdf->noTienda  = 'somevalue';
$pdf->noPedido  = 'somevalue';

答案 1 :(得分:0)

你做错了!应该是这样的:

$pdf->DocNum = $DocNum;
$pdf->cliente = $cliente;
$pdf->noCliente = $noCliente; 
$pdf->noTienda = $noTienda;
$pdf->noPedido = $noPedido;

Suerte!