PHP error in wordpress when using the command use


I add a code that uses the following string in the functions.php file

use Google\Spreadsheet\DefaultServiceRequest;

And when I save the file it gives me an error: Parse error: syntax error, unexpected 'use' (T_USE)

I use composer and the use has to go inside the function because if I take it out, I think that's why I do not add things to the sheet.

asked by AitorUdabe 03.10.2016 в 18:28

1 answer


To be able to use use or in other words "import" or "include" a class you need a namespace:


namespace foo;

use Google\Spreadsheet\DefaultServiceRequest;

The design that wordpress uses for the functions.php file does not allow to use use , since it is nothing more than a compilation of functions, without a namespace or a defined class.

You can see more information in the PHP documentation: link

answered by 03.10.2016 в 18:39