0

I have done multiples tests on a simple PHP page and it works pretty well. PhpSpreadsheet is pretty cool.

Then I wanted to add my code as a function to call it whenever I need to. However, I get this error now : syntax error, unexpected 'use' (T_USE). I'm not very familiar with the usecommand and I don't understand this error as well.

Here is the part which is getting an error (basically the start) :

function exportCSV($idNote) {
 require './vendor/autoload.php';
 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
 ...
}
  • 2
    Hello and welcome to SO! Try to move the `require` and the `use` out of the `function() {}` and to the top of the file. – Johannes Jul 31 '20 at 07:51
  • 2
    Does this answer your question? [PHP parse/syntax errors; and how to solve them](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – meewog Jul 31 '20 at 07:53
  • Thanks for the welcome and the quick reply! Indeed, it was the problem. I had to call PhpSpreadsheet outside of the function. –  Jul 31 '20 at 08:00

0 Answers0