PHP Fpdi 错误 "unexpected T_USE, expecting T_FUNCTION"

PHP Fpdi error "unexpected T_USE, expecting T_FUNCTION"

我正在尝试将两个 pdf 与 fpdi 和 fpdf 合并,但出现错误,而且我没有找到任何相关信息。我从 https://www.setasign.com/products/fpdi/demos/concatenate-fake/ 中获取了基本代码 我也在使用 CodeIgniter。

这是我的代码:

use setasign\Fpdi\Fpdi;
require_once(APPPATH. 'third_party/fpdf/fpdf.php');
require_once(APPPATH. 'third_party/fpdi/src/autoload.php');

$files = array($this->internalURL . "assets/uploadedContent/Test.pdf", $this->internalURL . "assets/uploadedContent/Test.pdf");
$pageCount = 0;


class ConcatPdf extends Fpdi
{
    public $files = array();

    public function setFiles($files)
    {
        $this->files = $files;
    }

    public function concat()
    {
        foreach($this->files AS $file) {
            $pageCount = $this->setSourceFile($file);
            for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
                $pageId = $this->ImportPage($pageNo);
                $s = $this->getTemplatesize($pageId);
                $this->AddPage($s['orientation'], $s);
                $this->useImportedPage($pageId);
            }
        }
    }
}

$pdf = new ConcatPdf();
$pdf->setFiles($files);
$pdf->concat();

$pdf->Output('I', './assets/uploadedContent/concat.pdf');

我得到了这个错误:

Parse error: syntax error, unexpected T_USE, expecting T_FUNCTION in /var/www/sites/***********/public/application/third_party/fpdi/src/Fpdi.php on line 27

错误来自 Fpdi 文件的这一行:

use FpdiTrait;

不知道是我的还是?

您正在使用 outdated PHP version。更新到最新版本。 FPDI 2 支持 PHP 5.6 及更高版本。