I am using dompdf and getting the following error: Parse error: syntax error, Unexpected 'use' (T_USE) in the line that references the namespace

Asked

Viewed 484 times

0

function contasApagar() {

        $fornecedorDAO = new fornecedoresDAO();
        $retfornecedor = $fornecedorDAO->buscarTodos();

        $forma_pagtoDAO = new forma_pagtoDAO();
        $retformapagamento = $forma_pagtoDAO->buscarTodas();

        $contaDAO = new contas_pagarDAO();
        $retorno = $contaDAO->filtrarData();


        // include autoloader
        require_once "vendor/autoload.php";

        //referenciando o namespace
        use  Dompdf \ Dompdf ;

        // instanciando o dompdf
        $dompdf = new Dompdf();

        //lendo o arquivo HTML correspondente
        $html = file_get_contents('visao/relatorios/contasApagar_pdf.php');
        //require_once "visao/relatorios/contasApagar_pdf.php";

        //inserindo o HTML que queremos converter
        $dompdf->loadHtml($html);

        //Definindo o tipo de fonte padrão
        $dompdf->set_option('defaultFont', 'Times New Roman');

        // Definindo o papel e a orientação
        $dompdf->setPaper('A4', 'portrait');

        // Renderizando o HTML como PDF
        $dompdf->render();

        // Enviando o PDF para o browser
        $dompdf->stream();

}
  • I think you have something related here: https://answall.com/q/51014/8063

  • I may be wrong, but namespace and use statements is usually at the beginning of the file

  • If I were to guess, I would say that use should be done this way: function contasApagar() use (Dompdf\Dompdf) { /* ... */ }, but it’s just an idea. But why not declare the use of the class at the beginning of the file?

  • use and namespace is at the top of the file.

  • Solved use namespace is at the top of the file.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.